From: Michael J. <mg...@un...> - 2002-12-10 14:16:49
|
Hi, I wrote my own notification script, which works wonders from command line. But doesn't seem to work with Netsaint. I added it in the command.cfg file. Here is how it works... command[host-notify]=/usr/bin/send_message '$HOSTNAME$ $HOSTADDRESS$ is $HOSTSTATE$! $OUTPUT$' $CONTACTPAGER$ 2> /var/log/message.err > /var/log/message.log I can run the script as root and a normal user from the command line and I even su-ed to the netsaint user to run the script and that worked. Here is the basic part of the script, I removed IP addresses and ports and how the message is formed, because that is unnecessary information. #!/usr/bin/perl ####################### use strict; use IO::Socket; ##### Date for logging my ($s, $m, $h, $D, $M, $Y) = localtime(time); my $date = sprintf "%4d/%02d/%02d %02d:%02d:%02d", $Y+1900, $M+1, $D, $h, $m, $s; #### Read in variables my $text = shift; my $phone = shift; #### Format the message my $output = &create_message ($phone, $text); #### Send the message &send_message ($output); ######################## END OF MAIN ########################### ########################################################## sub create_message{ #### Form the message <snip> return $message; } ########################################################## ########################################################## sub send_message{ #### Send the message my ($message) = @_; my $host = "IP ADDRESS"; my $port = "PORT"; my $socket = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port, Proto => 'tcp', Type => SOCK_STREAM) or die "[$date] Couldn't connect to $host:$port : $@ \n"; print $socket "$message" or die "[$date] Couldn't send message to $host:$port\n"; my $answer = <$socket>; close ($socket) or die "[$date] Couldn't close socket with $host:$port\n"; } ########################################################## Here are the permissions on the file: -r-xr-xr-x 1 root root 3643 Dec 9 11:33 /usr/bin/send_message Thanks, Michael |