Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Nagios Server Monitoring in SL

Hiro David
Registered User
Join date: 2 Oct 2005
Posts: 10
09-28-2006 13:13
I like to keep an eye on my systems with nagios. It pages me if things go wrong, however, I thought it would be cool to have an in-world display of system status. I put this together fairly quickly to get it going. I know it's sloppy code and I could do a lot more with it, but for now this is where it's at...

You have a perl script on your nagios machine that runs out of cron at intervals and examines your retention.dat file. In-world, you have a nagios_root prim and one prim for each host you're monitoring. Set the name of the host in the Description field. Drop the nagios_root script in the root object, then touch it and it will give you the key, which you then put in the perl script. Also you can put in a path to an ignore file with hostnames and it wont send those. There are a couple of paths to update in the perl script as well.

Sorry it's kinda sloppy atm but I thought I'd share anyhow....

Perl Script For The Host
CODE

#!/usr/bin/perl

$retention = "/usr/local/nagios/var/retention.dat"; # <--- retention file
$pwd = `pwd`;
$pwd =~ s/\n//;
$cp = `cp $retention $pwd`;
$sl = "4f143c21-a54e-47da-c211-750a07b89230"; # <--- your object key here
@ignore_data = `cat /usr/local/src/slagios/ignore`; # < ---- path to ignore file
foreach $host(@ignore_data){
$host =~ s/\n//;
$ignored{$host} = 1;
}

@data = `cat $retention`;
$lasthost = "";
$hostgrab = 0;
$servicegrab = 0;
foreach $line(@data){
$line =~ s/\n//;
if($line =~ /^host {/){
$hostgrab = 1;
}
if($hostgrab =~ /1/){
if($line =~ /host_name/){
($junk,$host) = split(/=/,$line);
$lasthost = $host;
push(@hosts,$host);
}
if($line =~ /current_state/){
($junk,$state) = split(/=/,$line);
if($state =~ /0/){$state = "UP";} else { $state = "DOWN";};
$host_states{$lasthost} = $state;
}
if($line =~ /}/ && $hostgrab =~ /1/){
$hostgrab = 0;
}
}

if($line =~ /^service {/){
$servicegrab = 1;
}
if($servicegrab =~ /1/){
if($line =~ /host_name/){
($junk,$host) = split(/=/,$line);
$lasthost = $host;
}
if($line =~ /service_description/){
($junk,$service) = split(/=/,$line);

}
if($line =~ /current_state/){
($junk,$state) = split(/=/,$line);

if($state =~ /1/){
$services{$lasthost} = 1;
}
}
}
if($line =~ /}/ && $servicegrab =~ /1/){
$servicegrab = 0;
};
}

$body = "";
$x = 0;
$addy = $sl . "@" . "lsl.secondlife.com";

foreach $host(@hosts){
if(! $ignored{$host}){
$string = $host . ":::Host:::" . $host_states{$host} . "\n";
if($x !~ /10/){
$body = $body . " " . $string;
} else {
$x = 0;
$mail = `echo \"$body\"\|mail -s \" \" $addy`;
#print "$body ";
$body = "";
}
$x = $x + 1;
};
};
$x = 0;
$body = "";
$string = "";
foreach $host(@hosts){
if(! $ignored{$host}){
if($services{$host} =~ /1/){
$string = $host . ":::Services:::Problem\n";
}
if($x !~ /10/){
$body = $body . " " . $string;
} else {
$x = 0;
if($string !~ /^$/){
$mail = `echo \"$body\"\|mail -s \" \" $addy`;
}

$body = "";
}
$x = $x + 1;
};
};


The Nagios Root Prim Script

CODE

integer debug = 0;
integer channel = 424242;

shoutout(list data)
{
integer x = 0;
for(x=0;x<llGetListLength(data);x++)
{
llSay(channel,llList2String(data,x));
if(debug)
{
llSay(0,llList2String(data,x));
}
}


}
default
{
state_entry()
{
llSetTimerEvent(10);
llSetText("Nagios",<0,0,1>,1.0);
llGetNextEmail("","");
}

touch_start(integer total_number)
{
llSay(0,(string)llGetKey());
}
timer()
{
llGetNextEmail("","");
}

email(string time, string address, string subj, string message, integer num_left)
{

// llSay(channel,message);
list data = llParseString2List(message,[" "],[""]);
shoutout(data);
llGetNextEmail("","");
}
}


The Nagios Host Prim
CODE

integer channel = 424242;

default
{
state_entry()
{
llListen(channel,"NagiosRoot","","");
llSetText(llGetObjectDesc(),<1,1,1>,1.0);
}

listen(integer channel,string name,key id,string message)
{
list data = llParseString2List(message,[":::"],[""]);
if(llList2String(data,0) == llGetObjectDesc())
{
list time = llParseString2List(llGetTimestamp(),["T"],[""]);
llSetText(llGetObjectDesc() + "\n" + llList2String(time,0) + "\n" + llList2String(time,1),<1,1,1>,1.0);
if(llList2String(data,1) == "Host" && llList2String(data,2) == "UP")
{
llSetColor(<0,1,0>,ALL_SIDES);

}
if(llList2String(data,1) == "Host" && llList2String(data,2) == "DOWN")
{
llSetColor(<1,0,0>,ALL_SIDES);
llSetText(llGetObjectDesc() + "\n" + "HOST DOWN",<1,0,0>,1.0);
}
if(llList2String(data,1) == "Services" && llList2String(data,2) == "Problem")
{
llSetColor(<1,0,0>,ALL_SIDES);
llSetText(llGetObjectDesc() + "\n" + "SERVICE PROBLEM",<1,0,0>,1.0);
}
}
}
}



again, sorry for the slop
Ohforf Uram
n00b
Join date: 27 Jun 2006
Posts: 82
09-28-2006 13:37
Question : what is Nagios ?
I answer myself :)
From: someone

Nagios is a host and service monitor designed to inform you of network problems before your clients, end-users or managers do. It has been designed to run under the Linux operating system, but works fine under most *NIX variants as well.
_____________________
Hiro David
Registered User
Join date: 2 Oct 2005
Posts: 10
oops
09-28-2006 14:17
guess I couldve said something to that effect eh?