Thursday, May 23rd 2013, 6:19pm UTC+2

You are not logged in.

  • Login
  • Register

Rene Storm

Intermediate

Posts: 524

Gender: male

Location: Hamburg

Number of monitoring servers: some

Hobbies: kitesurfing, buggykiting, snowboard,climbing,sleeping

Nagios Version: 3

Distributed monitoring: Ja

Redundant monitoring: Ja

Number of hosts: 800

Number of services: 8000

OS: Linux

Plugin Version: latest

NagVis Version: latest

NDO Version: NO MORE ;o)

1

Wednesday, June 27th 2012, 10:31am

Nagios Hardware Überwachung mit Hilfe von HPSim

Moin,

ich hatte ja schon mal geschrieben, das ich die Hardware Überwachung gerne unseren HP System Insigth Manager überlasse. (Pre-Failure Warrenty usw.)
Wie man die Daten aus der Sim Datenbank ins Nagios bekommt, findet ihr hier im Froum.

Jetzt wollte ich mal den Weg zurück zeigen, wie man Hosts automatisch aus einer Nagios Konfiguration in den Sim aufnimmt:
Benötigt (ndo, ido etc)

Vorgehen -> auf dem nagios Server erstellt man eine Webseite (php-script) das einem alle Hosts auflistet, die den Service "HPSIM" haben (dahinter befindet sich check_hpsim)
Diese PHP-Seite erstellt dann an kleines XML File mit allen Hostname und IPs

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
	$mysqlhost="localhost"; // MySQL-Host angeben
	$mysqluser="nagiosuser"; // MySQL-User angeben
	$mysqlpwd="nagiospassword"; // Passwort angeben

$connection=mysql_connect($mysqlhost, $mysqluser, $mysqlpwd) or die;
$mysqldb="nagios";
mysql_select_db($mysqldb, $connection) or die("Konnte die Datenbank nicht waehlen.");
	$sql = "select nagios_objects.name1,nagios_hosts.address
from nagios_objects,nagios_hosts,nagios_services
where is_active='1' AND
nagios_objects.name2 like ('HPSIM') AND
nagios_objects.object_id=nagios_services.service_object_id AND
nagios_services.host_object_id=nagios_hosts.host_object_id
order by name1,name2
";
$ip_query = mysql_query($sql) or die("Anfrage nicht erfolgreich");

printf("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
printf("<node-list>\n");

while ($ip = mysql_fetch_array($ip_query))
{
    	printf("<node name=\"%s\">\n",$ip['name1']);
    	printf("\t<sw-attribute name=\"IPAddress\">%s</sw-attribute>\n",$ip['address']);
    	printf("</node>\n\n");
}
printf('</node-list>');
?>

Output sollte wie folgt aussehen:

Source code

1
2
3
4
5
6
<?xml version="1.0" encoding="UTF-8"?>
<node-list>
<node name="nagioshost">
	<sw-attribute name="IPAddress">10.10.10.1</sw-attribute>
</node>
....



Auf dem Sim braucht man dann nur noch ein kleines Script regelmässig ausführen (wget für Windows o.ä. muss installiert sein):

Source code

1
2
wget http://guest:guest@nagios/hpsim.php -O hpsim.xml
mxnode  --user SimAdministrator --password SimPassword -a -f hpsim.xml  2>&1 > hpsim.log


Voila: Somit werden alle Hosts, die den Service HPSIM enthalten automatisch in SIM aufgenommen.

Gruss,
Rene





Anbei nochmal das check_hpsim script, wenn ihr nicht im Forum suchen mögt ;)
BTW: Der check braucht aber isql aus unixODBC.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash

IP=$1
SQL="isql hpsim2nagios user password"

no_host () {
 echo "Host: $IP does not exist in Database."
 exit 3
}

PROTOCOLS=""

SERVERINFO=`echo "select devices.Name,devices.productName,devices.ProductTypeStr,ipaddress.ipaddress,deviceProtocolInfo.SNMP,deviceProtocolInfo.HTTP,deviceProtocolInfo.DMI,deviceProtocolInfo.WBEM,deviceProtocolInfo.SSH from ipaddress,deviceProtocolInfo,devices WHERE ipaddress.devicekey=deviceProtocolInfo.DeviceKey AND devices.devicekey=ipaddress.devicekey AND ipaddress.ipaddress='${IP}'" | $SQL | grep -i $IP | grep -o -P "\|.*\|.*\|"`
#echo $SERVERINFO




DeviceName=`echo $SERVERINFO | cut -d"|" -f2 | xargs`
ProductName=`echo $SERVERINFO | cut -d"|" -f3 | xargs`
ProductTypeStr=`echo $SERVERINFO | cut -d"|" -f4 | xargs`
SNMP_int=`echo $SERVERINFO | cut -d"|" -f6 | xargs`
HTTP_int=`echo $SERVERINFO | cut -d"|" -f7 | xargs`
DMI_int=`echo $SERVERINFO | cut -d"|" -f8 | xargs`
WBEM_int=`echo $SERVERINFO | cut -d"|" -f9 | xargs`
SSH_int=`echo $SERVERINFO | cut -d"|" -f10 | xargs`

if [ "x$DeviceName" == "x" ];then
 no_host
fi

if [ "x$SNMP_int" == "x1" ];then PROTOCOLS="SNMP"; fi
if [ "x$HTTP_int" == "x1" ];then PROTOCOLS="$PROTOCOLS HTTP"; fi
if [ "x$DMI_int" == "x1" ];then PROTOCOLS="$PROTOCOLS DMI"; fi
if [ "x$WBEM_int" == "x1" ];then PROTOCOLS="$PROTOCOLS WBEM"; fi
if [ "x$SSH_int" == "x1" ];then PROTOCOLS="$PROTOCOLS SSH"; fi
if [ "x$_int" == "x1" ];then PROTOCOLS="$PROTOCOLS WBEM"; fi



RESULT=`echo "SELECT devices.fulldnsname,notices.noticeseverity,stringtablelarge.largevalue FROM devices,ipaddress,notices,noticetype,stringresource,stringtablelarge WHERE devices.overallstatus>'0' AND ipaddress.ipaddress='${IP}' AND devices.devicekey=ipaddress.devicekey AND notices.noticeseverity>='2' AND notices.noticeseverity!='100' AND notices.noticetype>235 AND devices.devicekey=notices.devicekey AND notices.state='2' AND notices.noticetype=noticetype.noticetype AND stringresource.resourcename=noticetype.typeidstr AND stringresource.subclass='label' AND stringresource.id=stringtablelarge.id AND stringtablelarge.language='en'  AND stringtablelarge.largevalue not like ('%Rising Threshold Passed%') ORDER BY notices.noticeseverity ASC;" | $SQL  | grep -v fulldnsname| grep -o -P "\|.*\|.*\|"`

#echo $RESULT
#exit

DNSNAME=`echo $RESULT | cut -d"|" -f2 | awk '{print $1}'`

if [ "x$DNSNAME" = "x" ]; then DNSNAME=$IP; fi

SEVERITY=`echo $RESULT | cut -d"|" -f3 | awk '{print $1}'`

ERRORMSG=`echo $RESULT | cut -d"|" -f4`

#echo DNSNAME $DNSNAME
#echo SEVERITY $SEVERITY
#echo ERRORMSG $ERRORMSG

if [ "x$SEVERITY" = "x" ]; then
 echo "HPSim Host ${DNSNAME}: ok. No Errors found."
 echo "${ProductTypeStr}:${DeviceName} (${ProductName}) Protocols:${PROTOCOLS} "
else
 echo "HPSim Host $DNSNAME: error. $ERRORMSG"
 echo "${ProductTypeStr}:${DeviceName} (${ProductName}) Protocols:${PROTOCOLS} "
 if [ $SEVERITY -le 3 ]; then
  exit 1
 else
  exit 2
 fi
fi


Output:
Status Information:HPSim Host host.domain.intra: error. (SNMP) Server Operational (6025)
Server:host (ProLiant DL380 G5) Protocols:SNMP HTTP SSH

This post has been edited 1 times, last edit by "Rene Storm" (Jun 27th 2012, 2:23pm)


Similar threads