perlcode 0 my %notifications=(); perlcode 0 $notifications{smtp}="@@DOSMTPNOTIFICATIONS@@"; perlcode 0 $notifications{snmp}="@@DOSNMPNOTIFICATIONS@@"; perlcode 0 my $fr='@@ADMINEMAIL@@'; perlcode 0 my $pwc='@@PHCEMAIL@@'; perlcode 0 my $hostname="@@HOSTNAME@@"; perlcode 0 my $traphost="@@TRAPHOST@@"; perlcode 0 my $snmpargs="-v 2c -c zimbra $traphost ''"; perlcode 0 my $snmptrap="/opt/zimbra/common/bin/snmptrap $snmpargs"; perlcode 0 my $snmpsvctrap="ZIMBRA-TRAP-MIB::zmServiceStatusTrap"; perlcode 0 my $snmpsvcname="ZIMBRA-MIB::zmServiceName"; perlcode 0 my $snmpsvcstatus="ZIMBRA-MIB::zmServiceStatus"; perlcode 0 use Zimbra::SMTP; perlcode 0 my %statuses=('started'=>1,'stopped'=>0); perlcode 0 sub donotify { my %args = (@_); if ($args{HOST} eq "localhost") {$args{HOST}=$hostname;}; if ($notifications{smtp}) { dosmtp(%args) if $args{SERVICE}; dodisksmtp(%args) if $args{DISK};}; if ($notifications{snmp}) {dosnmp(%args);}; } perlcode 0 sub dosmtp { my %args = @_; if (my $smtp=Zimbra::SMTP->new) {unless($smtp->send(from=>$fr,to=>$pwc,subject=>"Service $args{SERVICE} $args{STATUS} on $args{HOST}",message=>$args{MESSAGE})){warn "message send failed: ",$smtp->error}} else {warn "failed new Zimbra::SMTP: ",Zimbra::SMTP->error} } perlcode 0 sub dodisksmtp { my %args = (@_); print "SMTP notification: $args{MESSAGE}\n"; if (my $smtp=Zimbra::SMTP->new) {unless($smtp->send(from=>$fr,to=>$pwc,subject=>"Disk $args{DISK} at $args{UTIL}\% on $args{HOST}",message=>$args{MESSAGE})){warn "message send failed: ",$smtp->error}}else{warn "failed new Zimbra::SMTP: ",Zimbra::SMTP->error}} perlcode 0 sub dosnmp { my %args = (@_); print "SNMP notification: $args{MESSAGE}\n"; `$snmptrap $snmpsvctrap $snmpsvcname s $args{SERVICE} $snmpsvcstatus i $statuses{$args{STATUS}}`; } ignore /DEBUG/ watchfor /: Service status change: (\S+) (.*) changed from stopped to running/ donotify SERVICE=$2,STATUS=started,HOST=$1 watchfor /: Service status change: (\S+) (.*) changed from running to stopped/ donotify SERVICE=$2,STATUS=stopped,HOST=$1 watchfor /err: Disk warning: (\S+) (\S+) on device (\S+) at (\d+)/ donotify DISK=$2,UTIL=$4,HOST=$1 watchfor /crit: Disk warning: (\S+) (\S+) on device (\S+) at (\d+)/ donotify DISK=$2,UTIL=$4,HOST=$1