use standards-compliant tags php
[mdv_bs_web.git] / status.php
blob43fa3c9178ae01ae1ee5736c9b71ceae13a0ffca
1 <?php
3 require_once "common.inc.php";
5 function snmp_setup()
7 // Stolen from a php.net comment
9 // Return back the numeric OIDs, instead of text strings.
10 snmp_set_oid_numeric_print(1);
12 // Get just the values.
13 snmp_set_quick_print(TRUE);
15 // For sequence types, return just the numbers, not the string and numbers.
16 snmp_set_enum_print(TRUE);
18 // Don't let the SNMP library get cute with value interpretation. This makes
19 // MAC addresses return the 6 binary bytes, timeticks to return just the integer
20 // value, and some other things.
21 snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
25 * load
26 * logged in users
27 * processes
29 function server_status($server)
31 global $snmp_timeout;
33 /* Grab load */
34 $load = snmpget ($server, "public", "UCD-SNMP-MIB::laLoad.1", $snmp_timeout);
35 if ($load == NULL) {
36 /* Host is down - timed out */
37 return array ($ret, "", "", "");
41 /* Grab logged in users */
42 $users = snmpget ($server, "public", "HOST-RESOURCES-MIB::hrSystemNumUsers.0", $snmp_timeout);
44 /* Grab processes */
45 $processes = snmpget ($server, "public", "HOST-RESOURCES-MIB::hrSystemProcesses.0", $snmp_timeout);
47 return array (0, $users, $processes, $load);
51 * load
52 * free disk space
53 * logged in users
54 * processes
55 * enabled
57 function node_status($buildnode)
59 global $snmp_timeout;
61 /* Grab load */
62 $load = snmpget ($buildnode, "public", "UCD-SNMP-MIB::laLoad.1", $snmp_timeout);
63 if ($load == NULL) {
64 /* Host is down - timed out */
65 return array ($ret, "", "", "", "", "");
68 /* Grab free disk space */
69 $disk_avail = snmpget ($buildnode, "public", "UCD-SNMP-MIB::dskAvail.1", $snmp_timeout);
70 $disk_total = snmpget ($buildnode, "public", "UCD-SNMP-MIB::dskTotal.1", $snmp_timeout);
71 $disk = sprintf ("%dG/%dG", $disk_avail/1024/1024, $disk_total/1024/1024);
73 /* Grab logged in users */
74 $users = snmpget ($buildnode, "public", "HOST-RESOURCES-MIB::hrSystemNumUsers.0", $snmp_timeout);
76 /* Grab processes */
77 $processes = snmpget ($buildnode, "public", "HOST-RESOURCES-MIB::hrSystemProcesses.0", $snmp_timeout);
79 /* Check if it's enabled */
80 /* Check if cron is running */
81 if (!file_exists ("/var/run/crond.pid")) {
82 $enabled = FALSE;
84 /* Check if the node is really enabled */
85 else {
86 // Force always enabled, as we can't parse upload.conf anymore :(
87 $enabled = TRUE;
89 exec ('/bin/grep -q "^[ ]\+'.$buildnode.'[ ]\+=" /home/mandrake/.upload.conf',
90 $output, $enabled);
91 if ($enabled) {
92 $enabled = FALSE;
94 else {
95 $enabled = TRUE;
100 return array (0, $enabled, $users, $processes, $load, $disk);
117 // Setup snmp library
118 snmp_setup();
120 // Build the page
121 page_header("status");
124 <center>
125 <h3>Build system: servers status</h3>
126 <?php
129 * SERVERS
131 $servers = array (
132 "kenobi",
133 "svn"
136 $server_status = array();
138 foreach ($servers as $server) {
139 $server_status[$server] = server_status ($server);
143 <table style='text-align: right;'>
144 <tr>
145 <th>Server</th>
146 <th>Online</th>
147 <th>Users</th>
148 <th>Processes</th>
149 <th>Current load</th>
150 </tr>
151 <?php
153 foreach ($server_status as $server => $status) {
154 $online = !$status[0] ? "Yes" : "No";
155 echo "<tr>".
156 "<th>$server</th>".
157 "<td>$online</td>".
158 "<td>${status[1]}</td>".
159 "<td>${status[2]}</td>".
160 "<td>${status[3]}</td>".
161 "<tr>\n";
165 </table>
166 <?php
170 * NODES
172 $nodes = array (
173 "n1",
174 "n2",
175 "n3",
176 "n4",
177 "n5",
178 "celeste",
179 "klodia"
182 $node_status = array();
184 foreach ($nodes as $node) {
185 $node_status[$node] = node_status ($node);
189 <br>
190 <h3>Build system: build nodes status</h3>
191 <table style='text-align: right;'>
192 <tr>
193 <th>Node</th>
194 <th>Online</th>
195 <th>Enabled</th>
196 <th>Users</th>
197 <th>Processes</th>
198 <th>Current load</th>
199 <th>Disk usage</th>
200 </tr>
201 <?php
203 foreach ($node_status as $node => $status) {
204 $online = !$status[0] ? "Yes" : "No";
205 $enabled = $status[1] ? "Yes" : "No";
206 echo "<tr>".
207 "<th>$node</th>".
208 "<td>$online</td>".
209 "<td>$enabled</td>".
210 "<td>${status[2]}</td>".
211 "<td>${status[3]}</td>".
212 "<td>${status[4]}</td>".
213 "<td>${status[5]}</td>".
214 "<tr>\n";
218 </table>
219 </center>
220 <?php
222 page_footer();