ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/reports/php/latest/latest.php
Revision: 1.42
Committed: Sun Oct 13 12:41:16 2002 UTC (22 years, 1 month ago) by tdb
Branch: MAIN
Changes since 1.41: +12 -9 lines
Log Message:
Updated the "latest data" page to link to the newer graphs.php script
rather than the obselete browser.php script.

File Contents

# User Rev Content
1 pjm2 1.1 <?php
2    
3 tdb 1.37 #
4     # i-scream central monitoring system
5 tdb 1.41 # http://www.i-scream.org.uk
6 tdb 1.37 # Copyright (C) 2000-2002 i-scream
7     #
8     # This program is free software; you can redistribute it and/or
9     # modify it under the terms of the GNU General Public License
10     # as published by the Free Software Foundation; either version 2
11     # of the License, or (at your option) any later version.
12     #
13     # This program is distributed in the hope that it will be useful,
14     # but WITHOUT ANY WARRANTY; without even the implied warranty of
15     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16     # GNU General Public License for more details.
17     #
18     # You should have received a copy of the GNU General Public License
19     # along with this program; if not, write to the Free Software
20     # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21     #
22    
23 pjm2 1.1 # Navigation for the i-scream reports.
24     # pjm2@ukc.ac.uk
25     #
26     # CONFIGURABLE CONSTANTS: -
27    
28     include("latest_config.inc.php");
29    
30     #
31     # END CONFIGURATION
32    
33 pjm2 1.18 include("iutils.inc.php");
34 pjm2 1.1
35 pjm2 1.9 function printLine($title) {
36 pjm2 1.19 echo "<hr style=\"color:#9999ff;\">";
37 pjm2 1.9 echo "<b>$title</b>";
38 pjm2 1.6 }
39    
40 pjm2 1.1
41 tdb 1.42 function showStat($title, $value, $input, $graph="") {
42 pjm2 1.24
43     $report = $value;
44    
45 pjm2 1.28 $value = getPregMatch($value, $input);
46 tdb 1.38 if (!isset($value)) {
47 pjm2 1.8 $value = "<i><font color=\"#999999\">not sent</font></i>";
48 pjm2 1.1 }
49     ?>
50     <table border="0" width="100%">
51     <tr>
52 pjm2 1.24 <td width="50%" align="right" valign="top">
53     <b><?=$title?></b>
54     </td>
55     <td width="50%" align="left" valign="top">
56     <? if (preg_match("/^[0-9]+\.?[0-9]*$/", $value)) {
57 tdb 1.42 linkToHistory($graph);
58 pjm2 1.24 } ?>
59     <?=$value?></td>
60 pjm2 1.1 </tr>
61     </table>
62     <?
63     }
64    
65    
66 tdb 1.42 function linkToHistory($graph) {
67 pjm2 1.20 global $machine;
68 tdb 1.42 if(!empty($graph)) {
69     echo <<<EOT
70     <a href="graphs.php?machine_name=$machine&graph=$graph&submit=Show"><img src="minichart.gif" alt="View historical graphs of this data" width="20" height="20" border="0"></a>
71 pjm2 1.20 EOT;
72 tdb 1.42 }
73 pjm2 1.20 }
74    
75    
76 pjm2 1.28 # show all disk information.
77     function showDisks($diskRoot, $units, $input) {
78     include("latest_config.inc.php");
79    
80     $i = 0;
81     while(1) {
82     $name = getPregMatch("$diskRoot.p$i.attributes.name", $input);
83 pjm2 1.31 $mount = getPregMatch("$diskRoot.p$i.attributes.mount", $input);
84     if ($name || $mount) {
85     $used = "$diskRoot.p$i.attributes.used";
86     $kbytes = "$diskRoot.p$i.attributes.kbytes";
87 tdb 1.42 $graph = preg_replace("/_/", "$hex_underscore", $mount);
88     $graph = preg_replace("/\//", "$hex_slash", $graph);
89     showBar("$name<br>($mount)", $used, $kbytes, $units, $input, "disk-$graph");
90 pjm2 1.28 }
91 pjm2 1.30 else {
92     break;
93     }
94 pjm2 1.28 $i++;
95     }
96     }
97    
98     # Return a preg_match result.
99     function getPregMatch($value, $input) {
100 pjm2 1.29 preg_match("/$value=([^\,\}]*)[\,\}]/", $input, $matches);
101 pjm2 1.28 return $matches[1];
102     }
103    
104    
105 pjm2 1.1 # show a bar-represented value.
106 tdb 1.42 function showBar($title, $value, $max, $units, $input, $graph="", $arrange='normal') {
107 pjm2 1.1
108     include("latest_config.inc.php");
109    
110 pjm2 1.22 $report = $value;
111    
112 pjm2 1.28 $value = getPregMatch($value, $input);
113 pjm2 1.1 if (!is_int($max)) {
114 pjm2 1.28 $max = getPregMatch($max, $input);
115 pjm2 1.1 }
116 tdb 1.40 if (!isset($value) || !isset($max)) {
117 pjm2 1.1 return;
118     }
119    
120 pjm2 1.26 if ($arrange == 'swap') {
121 pjm2 1.27 $value = $max - $value;
122 pjm2 1.26 }
123 pjm2 1.27
124 tdb 1.40 if(empty($max)) {
125 pjm2 1.35 $width = 1;
126 tdb 1.40 }
127     else {
128     $width = intval($max_width * $value / $max);
129     if ($width < 1) {
130     $width = 1;
131     }
132 pjm2 1.35 }
133    
134 pjm2 1.1 ?>
135 pjm2 1.10 <table border="0" cellpadding="0" cellspacing="0" align="center">
136 pjm2 1.1 <tr>
137 tdb 1.42 <td colspan="2"><? linkToHistory($graph); ?> <b><?=$title?></b> <font size="2">(<?=$value?><?=$units?>)</font></td>
138 pjm2 1.1 </tr>
139     <tr>
140     <td colspan="2" bgcolor="#eeeeff"><img src="<?=$barImage?>" border="0" height="20" width="<?=$width?>"></td>
141     </tr>
142     <tr>
143     <td colspan="2"><img src="<?=$scaleImage?>" border="0" height="11" width="<?=$max_width?>"></td>
144     </tr>
145     <tr>
146 pjm2 1.13 <td align="left">0<?=$units?></td>
147     <td align="right"><?=$max?><?=$units?></td>
148 pjm2 1.1 </tr>
149 pjm2 1.15 <tr>
150     <td colspan="2">&nbsp;</td>
151     </tr>
152 pjm2 1.1 </table>
153     <?
154     }
155    
156    
157     ?>
158    
159     <? include($titleHTML); ?>
160    
161 pjm2 1.12 <? printLine("Display the latest information received from a host"); ?>
162 pjm2 1.1
163     <form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>">
164     <?
165    
166 pjm2 1.5 $file_array = getdirArray($latestDirectory,'asort');
167 pjm2 1.1 print "<select size=\"1\" name=\"machine\">";
168     if ($machine) { ?>
169     <option selected value="<? echo $machine ?>"><? echo $machine ?></option>
170     <option value="">----------------</option>
171     <? }
172     foreach($file_array as $file_name) {
173 pjm2 1.3 #if (is_dir($file_name)) {
174 pjm2 1.1 print "<option value=\"$file_name\">$file_name</option>";
175 pjm2 1.3 #}
176 pjm2 1.1 }
177     print "</select>";
178    
179     ?>
180     <input type="submit" name="submit" value="Display">
181     </form>
182    
183     <? if ($machine) {
184    
185 pjm2 1.12 $last_modified = filemtime("$latestDirectory/$machine/$latestData");
186     clearstatcache();
187     $data_age = time() - $last_modified;
188    
189 pjm2 1.36 $last_modified = date("l jS F Y - g:ia", $last_modified);
190 pjm2 1.12
191     if ($data_age > $warning_age) {
192     $warning = <<<EOT
193     <br>
194     <font color="red"><b>
195     Warning:
196     </b></font>
197     This realtime report is too old to be considered recent
198     EOT;
199     }
200    
201     echo <<<EOT
202 pjm2 1.16 <table border="0" bgcolor="#000066" cellpadding="3" cellspacing="1">
203 pjm2 1.12 <tr>
204     <td bgcolor="#000066">
205     &nbsp;
206     </td>
207     <td bgcolor="#ffffcc">
208     <font face="arial,sans-serif" size="2">
209 pjm2 1.24 <b>Receipt date:</b> $last_modified
210 pjm2 1.12 $warning
211     </font>
212     </td>
213     </tr>
214     </table>
215     EOT;
216    
217 pjm2 1.1 # Read the file.
218 pjm2 1.25 if (file_exists("$latestDirectory/$machine/$latestData")) {
219     $input = file("$latestDirectory/$machine/$latestData");
220     # All we need is the first line if there is more than one line.
221     $input = $input[0];
222     }
223 pjm2 1.1
224 tdb 1.38 if (!isset($input)) {
225 pjm2 1.25 echo "<br><br>There are currently no latest details about <b>$machine</b>. Please notify your i-scream server administrator if you believe this to be incorrect.";
226 pjm2 1.1 }
227     else {
228     # Display the data specified in the display include.
229     include("latest_display.inc.php");
230     }
231 pjm2 1.9 }
232 pjm2 1.12
233 pjm2 1.1 ?>
234    
235 pjm2 1.16 <? printLine(""); ?>
236 pjm2 1.1
237     <? include($bottomHTML); ?>