FW: FW: NDOUtils and NDO2BD
Wheeler, JF (Jonathan)
J.F.Wheeler at rl.ac.uk
Tue Dec 12 15:39:05 CET 2006
> -----Original Message-----
> From: Jeff Sullivan [mailto:iceman at 30below.com]
> Sent: 12 December 2006 14:01
> To: Wheeler, JF (Jonathan)
> Subject: Re: [Nagios-users] FW: NDOUtils and NDO2BD
>
>
> That would be great.. Those darn NDO2DB tables really need a
> dictionary.map..
These queries are extracts from a PHP script; note that the database
name nagios is included because there are other queries in the script
using a different database. The first query is checking for the status
of a host (host name in $SHORT[$n]):
$got = mysql_query("select last_state_change from nagios.ndo_hoststatus,
".
"nagios.ndo_objects where host_object_id=object_id and ".
"name1='".$SHORT[$n]."' and
nagios.ndo_hoststatus.current_state=1");
if ($got and mysql_num_rows($got)) {
$st = "down"; $txt = "$node ($st - Nagios)";
All it is doing is checking if there is a record in ndo_hoststatus for
the host where ndo_hoststatus is 1; host_object_id is a field in
ndo_hoststatus which matches object_id in ndo_objects; name1 is the name
of the host from ndo_objects
The second query is doing something similar for alarms for hosts which
are not down:
# Check for Nagios alarms if system is not down
if (strncmp($st, "down", 4) != 0) {
$got = mysql_query("select output from nagios.ndo_servicestatus, ".
"nagios.ndo_objects where objecttype_id=2 and
name1='".$SHORT[$n]."'".
" and current_state=2 and service_object_id=object_id");
if ($got and mysql_num_rows($got)) { $st .= "_a"; }
In this query object_id, objecttype_id and name1 are fields in
ndo_objects (you need both objecttype_id and name1 because there is a
multi-field index built on objecttype_id and name1 in that order);
current_state and service_object_id are fields in ndo_servicestatus
This third query is extracting all the alarms for a host (this is a
different script so $SHORT is not an array here):
$got = mysql_query("select current_state, output, unix_timestamp() - ".
"unix_timestamp(last_hard_state_change) from nagios.ndo_objects, ".
"nagios.ndo_servicestatus where current_state!=0 and ".
"service_object_id=object_id and name1='".$SHORT."'");
if ($got and mysql_num_rows($got)) {
print "<div class=\"sub\">Alarms for
".htmlspecialchars($NODE)."</div>\n";
$warns = $crits = $unkns = "";
while ($r = mysql_fetch_row($got)) {
$txt1 = "<tr valign=\"top\"><td><span class=";
$txt2 = "</span></td> <td>$r[1]</td> <td nowrap><span
class=\"time\">".
prettytime($r[2])."</span></td></tr>\n";
switch ($r[0]) {
case 1: $warns .= $txt1."\"warn\">WARNING".$txt2; break;
case 2: $crits .= $txt1."\"crit\">CRITICAL".$txt2; break;
case 3: $unkns .= $txt1."\"unkn\">UNKNOWN".$txt2; break;
default: $unkns .= $txt1."\"unkn\">UNKNOWN (bad type)".$txt2;
}
}
print "<div><table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" ".
"width=\"100%\">\n$crits$warns$unkns</table></div>\n";
}
I hope that this helps. Please ask for more explanations if required.
Jonathan Wheeler
e-Science Centre
Rutherford Appleton Laboratory
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
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