Created
April 5, 2018 12:50
-
-
Save almirage/98fa682eae6af2ef226bbafbba408ad2 to your computer and use it in GitHub Desktop.
特定のディレクトリに最新ファイルが存在するかをチェックするNagios向けのPerlスクリプトです。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
$dirName = shift(@ARGV); | |
$okLimit = shift(@ARGV); | |
$warnLimit = shift(@ARGV); | |
if (!defined($dirName)) { | |
print ("ERROR: usage [dirname] [ok limit] [warn limit]\n"); | |
exit 3; | |
} | |
if (!-d $dirName || !-x $dirName) { | |
print ("ERROR: target dir doesn't exist or permission error\n"); | |
exit 3; | |
} | |
if (check($dirName, $okLimit)) { | |
printf("OK %s\n", getLabel($dirName)); | |
exit 0; | |
} | |
if (check($dirName, $warnLimit)) { | |
printf("WARNING %s\n", getLabel($dirName)); | |
exit 1; | |
} | |
printf("CRITICAL %s\n", getLabel($dirName)); | |
exit 2; | |
sub check { | |
my $dir = shift(@_); | |
my $th = shift(@_); | |
$cmd = "find $dir -cmin -$th -type f | wc -l"; | |
$cnt = `$cmd`; | |
chomp $cnt; | |
return 0 + $cnt; | |
} | |
sub getLabel { | |
my $dir = shift(@_); | |
$cmd = "find $dir -type f -exec date \"+%Y/%m/%d %H:%M\" -r {} \\; | sort -r | head -n 1"; | |
$r = `$cmd`; | |
chomp $r; | |
return $r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
定期メールがMaildirに正しく届いているかNagiosからチェックするのに使っています。
チェック時に指定時間(分)以内にファイルが生成されていればOK、ファイルがなければメールが滞っていると判断してCRITICALです。