Extended Host Notes
Jason Branscum
jasonb at teletouch.net
Thu Jun 17 18:22:48 CEST 2004
All:
I sent out a message a few days ago asking if people had found ways to put
"notes" in the notification email.. I got a lot of help and wanted to say
thank you!
So, with that, I took the suggestions and made a perl script to run a
SELECT from MySQL. You will need DBI and DBD::MYSQL installed for this
script to work. Just a contribution, nothing more :)
The perl script:
#!/path/to/perl
################################################################
# nagiosNotes.pl v0.01
# jasonb at teletouch.net
# Free free to modify this script to your heart's content,
# just remember it comes with no warranty. best o` luck.
################################################################
use DBI();
my ($sql, $noteSQL, $sqlUser, $sqlPass, $sqlHost, $sqlDatabase, $sqlTable);
my ($hostName, $notes, $usage, $debug, $debugOutput);
$debug = 0;
$debugOutput = "/tmp/nagiosNotes.debug";
$sqlUser = "mysqlUsername";
$sqlPass = "mysqlPassword";
$sqlHost = "localhost";
$sqlDatabase = "mysqlDb";
$sqlTable = "mysqlTable";
$echo = "/bin/echo";
$time = localtime;
$usage = "usage: nagiosNotes <hostname>";
$noteSQL = 0;
if (!$ARGV[0]) { print $usage; system("$echo \"died at $time, no arg
presented\">>$debugOutput"); die; }
$hostName = shift @ARGV;
chomp $hostname;
$hostName =~ tr/A-Z/a-z/;
if ($debug) { system("$echo \"$hostName requested at
$time\">>$debugOutput"); }
$noteSQL =
DBI->connect("DBI:mysql:database=$sqlDatabase;host=$sqlHost","$sqlUser","$sqlPass",{'RaiseError'=>
1});
$sql = $noteSQL->prepare("SELECT notes FROM $sqlTable WHERE (hostName =
'$hostName')");
$sql->execute();
while (my $ref = $sql->fetchrow_hashref()) { $notes = $ref->{'notes'}; }
$sql->finish();
print "$notes";
The SQL Structure:
CREATE TABLE `hostnotes` (
`hostName` varchar(32) NOT NULL default '',
`notes` varchar(255) NOT NULL default ''
) TYPE=MyISAM;
The example row (remember to add new rows with the hostname in _lowercase_):
INSERT INTO `hostnotes` VALUES ('router.mynetwork.com', 'CALL SOMEISP IF
LINK GOES DOWN, 555-1212');
And finally, add this into your service/host notify commands in
misccommands.cfg (assuming the script is in /usr/local/bin)
\nNotes: `/usr/local/bin/nagiosNotes.pl $HOSTNAME$`.. mine all-in-all
looks like this:
/usr/bin/printf "%b" "Notification Type: $NOTIFICATIONTYPE$\nHost:
$HOSTNAME$\nAddress: $HOSTADDRESS$\nService: $SERVICEDESC$\nState:
$SERVICESTATE$\nNotes: `/usr/local/bin/nagiosNotes $HOSTNAME$`\nTimestamp:
$DATETIME$\n\nPlugin Output: $OUTPUT$" | /usr/bin/mail -s
"$HOSTNAME$($HOSTALIAS$)/$SERVICEDESC$ is $SERVICESTATE$"
Enjoy
Jason
-------------------------------------------------------
This SF.Net email is sponsored by The 2004 JavaOne(SM) Conference
Learn from the experts at JavaOne(SM), Sun's Worldwide Java Developer
Conference, June 28 - July 1 at the Moscone Center in San Francisco, CA
REGISTER AND SAVE! http://java.sun.com/javaone/sf Priority Code NWMGYKND
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue.
::: Messages without supporting info will risk being sent to /dev/null
More information about the Users
mailing list