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