hide tab on none IPv4 objects
[racktables-contribs] / nagios.php
1 <?php
2 // Racktables Nagios Plugin v.0.1
3 // Copy this file into the plugin directory
4
5 // 2012-09-11 - Mogilowski Sebastian <sebastian@mogilowski.net>
6
7 // http://www.mogilowski.net/projects/racktables
8
9
10 # Settings
11 # -----------------------------------------------------------------------------------------
12 $nagios_user = 'nagiosadmin';
13 $nagios_password = 'nagios';
14 $nagios_url = 'https://localhost/nagios3';
15 $attribute_id = 10001;// use attribute id (string) as nagios hostname on remote call,
16 //useful when your racktables and nagios hosts are not named the same
17 // remember to assign attribute to specific objects (like server)
18 # -----------------------------------------------------------------------------------------
19
20 $tab['object']['Nagios'] = 'Nagios';
21 $tabhandler['object']['Nagios'] = 'NagiosTabHandler';
22
23 function NagiosTabHandler()
24 {
25
26 global $nagios_user, $nagios_password, $nagios_url, $attribute_id;
27
28 # Load object data
29 assertUIntArg ('object_id', __FUNCTION__);
30 $object = spotEntity ('object', $_REQUEST['object_id']);
31
32 $attributes = getAttrValues ($_REQUEST['object_id']);
33 if(@strlen($attributes[$attribute_id]['value'])) {.
34 $target = $attributes[$attribute_id]['value'];
35 } else {
36 $target = $object['name'];
37 }
38
39 $nagios_url_cgi = $nagios_url . '/cgi-bin/status.cgi?host=%%NAGIOS%%';
40 $nagios_url_cgi = str_replace("%%NAGIOS%%", urlencode($target), $nagios_url_cgi);
41
42 # Curl request
43 $ch = curl_init();
44 curl_setopt($ch, CURLOPT_URL, $nagios_url_cgi);
45 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
46 curl_setopt($ch, CURLOPT_USERPWD, "$nagios_user:$nagios_password");
47 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
48 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
49 $output = curl_exec($ch);
50 $info = curl_getinfo($ch);
51 curl_close($ch);
52
53 # Remove unwanted tags & headline & hyperlinks
54 $output = strip_tags($output, '<p><div><table><tr><td><th><br><a>');
55 $output = substr ( $output , strpos($output,'<'));
56 $output = str_replace("HREF='", "onclick='return popup(this.href);' target='_blank' HREF='$nagios_url/cgi-bin/", $output);
57 $output = str_replace("href='", "onclick='return popup(this.href);' target='_blank' href='$nagios_url/cgi-bin/", $output);
58 $output = str_replace($nagios_url."/cgi-bin/http://www.nagios.org", "http://www.nagios.org", $output);
59
60 # Output
61 htmlExtras();
62 echo '<div class=portlet><h2>Nagios</h2>'.$output.'</div>';
63
64 }
65
66 function htmlExtras () {
67
68 echo '
69 <script type="text/javascript">
70 function popup (url) {
71 popup = window.open(url, "Nagios", "width=1024,height=800,resizable=yes");
72 popup.focus();
73 return false;
74 }
75 </script>
76 <style type="text/css">
77 .status { font-family: arial,serif; background-color: white; color: black; }
78
79 .errorMessage { font-family: arial,serif; text-align: center; color: red; font-weight: bold; font-size: 12pt; }
80 .errorDescription { font-family: arial,serif; text-align: center; font-weight: bold; font-size: 12pt; }
81 .warningMessage { font-family: arial,serif; text-align: center; color: red; font-weight: bold; font-size: 10pt; }
82 .infoMessage { font-family: arial,serif; text-align: center; color: red; font-weight: bold; }
83
84 .infoBox { font-family: arial,serif; font-size: 8pt; background-color: #C4C2C2; padding: 2; }
85 .infoBoxTitle { font-family: arial,serif; font-size: 10pt; font-weight: bold; }
86 .infoBoxBadProcStatus { font-family: arial,serif; color: red; }
87 A.homepageURL:Hover { font-family: arial,serif; color: red; }
88
89 .linkBox { font-family: arial,serif; font-size: 8pt; background-color: #DBDBDB; padding: 1; }
90
91 .filter { font-family: arial,serif; font-size: 8pt; background-color: #DBDBDB; }
92 .filterTitle { font-family: arial,serif; font-size: 10pt; font-weight: bold; background-color: #DBDBDB; }
93 .filterName { font-family: arial,serif; font-size: 8pt; background-color: #DBDBDB; }
94 .filterValue { font-family: arial,serif; font-size: 8pt; background-color: #DBDBDB; }
95
96 .itemTotalsTitle { font-family: arial,serif; font-size: 8pt; text-align: center; }
97
98 .statusTitle { font-family: arial,serif; text-align: center; font-weight: bold; font-size: 12pt; }
99 .statusSort { font-family: arial,serif; font-size: 8pt; }
100
101 TABLE.status { font-family: arial,serif; font-size: 8pt; background-color: white; padding: 2; }
102 TH.status { font-family: arial,serif; font-size: 10pt; text-align: left; background-color: #999797; color: #DCE5C1; }
103 DIV.status { font-family: arial,serif; font-size: 10pt; text-align: center; }
104 .statusOdd { font-family: arial,serif; font-size: 8pt; background-color: #DBDBDB; }
105 .statusEven { font-family: arial,serif; font-size: 8pt; background-color: #C4C2C2; }
106
107 .statusPENDING { font-family: arial,serif; font-size: 8pt; background-color: #ACACAC; }
108 .statusOK { font-family: arial,serif; font-size: 8pt; background-color: #33FF00; }
109 .statusRECOVERY { font-family: arial,serif; font-size: 8pt; background-color: #33FF00; }
110 .statusUNKNOWN { font-family: arial,serif; font-size: 8pt; background-color: #FF9900; }
111 .statusWARNING { font-family: arial,serif; font-size: 8pt; background-color: #FFFF00; }
112 .statusCRITICAL { font-family: arial,serif; font-size: 8pt; background-color: #F83838; }
113
114 .statusHOSTPENDING { font-family: arial,serif; font-size: 8pt; background-color: #ACACAC; }
115 .statusHOSTUP { font-family: arial,serif; font-size: 8pt; background-color: #33FF00; }
116 .statusHOSTDOWN { font-family: arial,serif; font-size: 8pt; background-color: #F83838; }
117 .statusHOSTDOWNACK { font-family: arial,serif; font-size: 8pt; background-color: #F83838; }
118 .statusHOSTDOWNSCHED { font-family: arial,serif; font-size: 8pt; background-color: #F83838; }
119 .statusHOSTUNREACHABLE { font-family: arial,serif; font-size: 8pt; background-color: #F83838; }
120 .statusHOSTUNREACHABLEACK { font-family: arial,serif; font-size: 8pt; background-color: #F83838; }
121 .statusHOSTUNREACHABLESCHED { font-family: arial,serif; font-size: 8pt; background-color: #F83838; }
122
123 .statusBGUNKNOWN { font-family: arial,serif; font-size: 8pt; background-color: #FFDA9F; }
124 .statusBGUNKNOWNACK { font-family: arial,serif; font-size: 8pt; background-color: #FFDA9F; }
125 .statusBGUNKNOWNSCHED { font-family: arial,serif; font-size: 8pt; background-color: #FFDA9F; }
126 .statusBGWARNING { font-family: arial,serif; font-size: 8pt; background-color: #FEFFC1; }
127 .statusBGWARNINGACK { font-family: arial,serif; font-size: 8pt; background-color: #FEFFC1; }
128 .statusBGWARNINGSCHED { font-family: arial,serif; font-size: 8pt; background-color: #FEFFC1; }
129 .statusBGCRITICAL { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
130 .statusBGCRITICALACK { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
131 .statusBGCRITICALSCHED { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
132 .statusBGDOWN { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
133 .statusBGDOWNACK { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
134 .statusBGDOWNSCHED { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
135 .statusBGUNREACHABLE { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
136 .statusBGUNREACHABLEACK { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
137 .statusBGUNREACHABLESCHED { font-family: arial,serif; font-size: 8pt; background-color: #FFBBBB; }
138
139 DIV.serviceTotals { font-family: arial,serif; text-align: center; font-weight: bold; font-size: 10pt; }
140 TABLE.serviceTotals { font-family: arial,serif; font-size: 10pt; background-color: white; padding: 2; }
141 TH.serviceTotals,A.serviceTotals { font-family: arial,serif; font-size: 10pt; background-color: white; text-align: center; background-color: #999797; color: #DCE5C1; }
142 TD.serviceTotals { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #e9e9e9; }
143
144 .serviceTotalsOK { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #33FF00; }
145 .serviceTotalsWARNING { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #FFFF00; font-weight: bold; }
146 .serviceTotalsUNKNOWN { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #FF9900; font-weight: bold; }
147 .serviceTotalsCRITICAL { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #F83838; font-weight: bold; }
148 .serviceTotalsPENDING { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #ACACAC; }
149 .serviceTotalsPROBLEMS { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: orange; font-weight: bold; }
150
151
152 DIV.hostTotals { font-family: arial,serif; text-align: center; font-weight: bold; font-size: 10pt; }
153 TABLE.hostTotals { font-family: arial,serif; font-size: 10pt; background-color: white; padding: 2; }
154 TH.hostTotals,A.hostTotals { font-family: arial,serif; font-size: 10pt; background-color: white; text-align: center; background-color: #999797; color: #DCE5C1; }
155 TD.hostTotals { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #e9e9e9; }
156
157 .hostTotalsUP { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #33FF00; }
158 .hostTotalsDOWN { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #F83838; font-weight: bold; }
159 .hostTotalsUNREACHABLE { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #F83838; font-weight: bold; }
160 .hostTotalsPENDING { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: #ACACAC; }
161 .hostTotalsPROBLEMS { font-family: arial,serif; font-size: 8pt; text-align: center; background-color: orange; font-weight: bold; }
162
163 .miniStatusPENDING { font-family: arial,serif; font-size: 8pt; background-color: #ACACAC; text-align: center; }
164 .miniStatusOK { font-family: arial,serif; font-size: 8pt; background-color: #33FF00; text-align: center; }
165 .miniStatusUNKNOWN { font-family: arial,serif; font-size: 8pt; background-color: #FF9900; text-align: center; }
166 .miniStatusWARNING { font-family: arial,serif; font-size: 8pt; background-color: #FFFF00; text-align: center; }
167 .miniStatusCRITICAL { font-family: arial,serif; font-size: 8pt; background-color: #F83838; text-align: center; }
168
169 .miniStatusUP { font-family: arial,serif; font-size: 8pt; background-color: #33FF00; text-align: center; }
170 .miniStatusDOWN { font-family: arial,serif; font-size: 8pt; background-color: #F83838; text-align: center; }
171 .miniStatusUNREACHABLE { font-family: arial,serif; font-size: 8pt; background-color: #F83838; text-align: center; }
172
173 .hostImportantProblem { text-align: left; font-family: arial; font-size: 8pt; background-color: #ff0000; color: black; text-decoration: blink; }
174 .hostUnimportantProblem { text-align: left; font-family: arial; font-size: 8pt; background-color: #ffcccc; color: black; }
175
176 .serviceImportantProblem { text-align: left; font-family: arial; font-size: 8pt; background-color: #ff0000; color: black; text-decoration: blink; }
177 .serviceUnimportantProblem { text-align: left; font-family: arial; font-size: 8pt; background-color: #ffcccc; color: black; }
178 </style>
179 ';
180
181 }
182
183 ?>