35 lines
1.2 KiB
Perl
35 lines
1.2 KiB
Perl
#!/usr/bin/perl
|
|
|
|
my $path="/usr/lib64/nagios/plugins";
|
|
my $log="/var/log/send_sms";
|
|
my $smspath="/var/spool/sms/outgoing";
|
|
|
|
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
|
|
my $smsfile="$smspath/out_" . sprintf("%4d-%02d-%02d_%02d-%02d-%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec);
|
|
|
|
if (system("$path/feiertage.sh") != 0) {
|
|
open LF, ">>$log" || die "Kann Logfile nicht schreiben!";
|
|
printf LF "### %4d-%02d-%02d %02d-%02d-%02d\n", $year+1900, $mon+1, $mday, $hour, $min, $sec;
|
|
printf LF "Keine Alarmierung ($path/feiertage.sh)!\n";
|
|
close LF;
|
|
exit 0;
|
|
}
|
|
|
|
my $host=$ARGV[0];
|
|
my $msg=$ARGV[1];
|
|
my $lvl=$ARGV[2];
|
|
|
|
open SMS, "<$path/sms_receiver" || die "Kann SMS Receiver Datei nicht schreiben!";
|
|
my $nr=<SMS>;
|
|
close SMS;
|
|
|
|
open FH, ">$smsfile" || die "Kann SMS Datei nicht schreiben!";
|
|
open LF, ">>$log" || die "Kann Logfile nicht schreiben!";
|
|
|
|
printf FH "To: %s\n\nHost/Service:\n%s\n\nStatus: %s\n\nNachricht:\n%s\n", $nr, $host, $lvl, $msg;
|
|
printf LF "### %4d-%02d-%02d %02d-%02d-%02d\n", $year+1900, $mon+1, $mday, $hour, $min, $sec;
|
|
printf LF "To: %s\n\nHost/Service:\n%s\n\nStatus: %s\n\nNachricht:\n%s\n", $nr, $host, $lvl, $msg;
|
|
|
|
close FH;
|
|
close LF;
|