ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/reports/php/latest/latest.php
(Generate patch)

Comparing projects/cms/source/reports/php/latest/latest.php (file contents):
Revision 1.8 by pjm2, Thu Mar 8 22:29:19 2001 UTC vs.
Revision 1.41 by tdb, Tue May 21 16:47:15 2002 UTC

# Line 1 | Line 1
1   <?php
2  
3 + #
4 + # i-scream central monitoring system
5 + # http://www.i-scream.org.uk
6 + # 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   # Navigation for the i-scream reports.
24   # pjm2@ukc.ac.uk
25   #
# Line 10 | Line 30 | include("latest_config.inc.php");
30   #
31   # END CONFIGURATION
32  
33 + include("iutils.inc.php");
34  
35 < # return an array of subdirectories from a directory.
36 < function getdirArray($dir='./',$sort='asort') {
37 <    global $dir_file_count;
17 <    if ( is_dir($dir) ) {
18 <        $fd = @opendir($dir);
19 <        while ( ($part = @readdir($fd)) == TRUE ) {
20 <            clearstatcache();
21 <            if ($part != "." && $part != "..") {
22 <                $dir_array[] = $part;
23 <            }
24 <        }
25 <        if($fd == TRUE) {
26 <            closedir($fd);
27 <        }
28 <        if (is_array($dir_array)) {
29 <            $sort($dir_array);
30 <            $dir_file_count = count($dir_array);
31 <            Return $dir_array;
32 <        } else {
33 <            Return FALSE;
34 <        }
35 <    } else {
36 <        Return FALSE;
37 <    }
35 > function printLine($title) {
36 >    echo "<hr style=\"color:#9999ff;\">";
37 >    echo "<b>$title</b>";
38   }
39  
40 function printLine() {
41    echo "<hr color=\"#9999ff\">";
42 }
40  
44
41   function showStat($title, $value, $input) {
42 <    preg_match("/$value=([^\,]*)[\,\}]/", $input, $matches);
43 <    $value = $matches[1];
44 <    if (empty($value)) {
42 >
43 >    $report = $value;
44 >
45 >    $value = getPregMatch($value, $input);
46 >    if (!isset($value)) {
47          $value = "<i><font color=\"#999999\">not sent</font></i>";
48      }
49      ?>
50          <table border="0" width="100%">
51            <tr>
52 <            <td width="50%" align="right" valign="top"><b><?=$title?></b></td>
53 <            <td width="50%" align="left" valign="top"><?=$value?></td>
52 >            <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 >                    linkToHistory($report);
58 >                } ?>
59 >              <?=$value?></td>
60            </tr>
61          </table>
62      <?
63   }
64  
65  
66 + function linkToHistory($report) {
67 +    global $machine;
68 +    $yesterday = date("Y-m-d", time() - 86400);
69 +    echo <<<EOT
70 +        <a href="browser.php?machine_name=$machine&report=$report&day=$yesterday&submit=Show"><img src="minichart.gif" alt="View yesterday's 24-hour chart" width="20" height="20" border="0"></a>
71 + EOT;
72 + }
73 +
74 +
75 + # show all disk information.
76 + function showDisks($diskRoot, $units, $input) {
77 +    include("latest_config.inc.php");
78 +
79 +    $i = 0;
80 +    while(1) {
81 +        $name = getPregMatch("$diskRoot.p$i.attributes.name", $input);
82 +        $mount = getPregMatch("$diskRoot.p$i.attributes.mount", $input);
83 +        if ($name || $mount) {
84 +            $used = "$diskRoot.p$i.attributes.used";
85 +            $kbytes = "$diskRoot.p$i.attributes.kbytes";
86 +            showBar("$name<br>($mount)", $used, $kbytes, $units, $input);
87 +        }
88 +        else {
89 +            break;
90 +        }
91 +        $i++;
92 +    }
93 + }
94 +
95 + # Return a preg_match result.
96 + function getPregMatch($value, $input) {
97 +    preg_match("/$value=([^\,\}]*)[\,\}]/", $input, $matches);
98 +    return $matches[1];
99 + }
100 +
101 +
102   # show a bar-represented value.
103 < function showBar($title, $value, $max, $input) {
103 > function showBar($title, $value, $max, $units, $input, $arrange='normal') {
104  
105      include("latest_config.inc.php");
106  
107 <    preg_match("/$value=([^\,]*)\,/", $input, $matches);
108 <    $value = $matches[1];
107 >    $report = $value;
108 >
109 >    $value = getPregMatch($value, $input);
110      if (!is_int($max)) {
111 <        preg_match("/$max=([^\,]*)\,/", $input, $matches);
71 <        $max = $matches[1];
111 >        $max = getPregMatch($max, $input);
112      }
113 <    if (empty($value) || empty($max)) {
113 >    if (!isset($value) || !isset($max)) {
114          return;
115      }
116  
117 <    $width = intval($max_width * $value / $max);
117 >    if ($arrange == 'swap') {
118 >        $value = $max - $value;
119 >    }
120  
121 +    if(empty($max)) {
122 +        $width = 1;
123 +    }
124 +    else {
125 +        $width = intval($max_width * $value / $max);
126 +        if ($width < 1) {
127 +            $width = 1;
128 +        }
129 +    }
130 +
131      ?>
132 <        <table border="0" cellpadding="0" cellspacing="0">
132 >        <table border="0" cellpadding="0" cellspacing="0" align="center">
133            <tr>
134 <            <td colspan="2"><b><?=$title?></b></td>
134 >            <td colspan="2"><? linkToHistory($report); ?> <b><?=$title?></b> <font size="2">(<?=$value?><?=$units?>)</font></td>
135            </tr>
136            <tr>
137              <td colspan="2" bgcolor="#eeeeff"><img src="<?=$barImage?>" border="0" height="20" width="<?=$width?>"></td>
# Line 88 | Line 140 | function showBar($title, $value, $max, $input) {
140              <td colspan="2"><img src="<?=$scaleImage?>" border="0" height="11" width="<?=$max_width?>"></td>
141            </tr>
142            <tr>
143 <            <td align="left">0</td>
144 <            <td align="right"><?=$max?></td>
143 >            <td align="left">0<?=$units?></td>
144 >            <td align="right"><?=$max?><?=$units?></td>
145            </tr>
146 +          <tr>
147 +            <td colspan="2">&nbsp;</td>
148 +          </tr>
149          </table>
150      <?
151   }
# Line 100 | Line 155 | function showBar($title, $value, $max, $input) {
155  
156   <? include($titleHTML); ?>
157  
158 < <hr weight="1" color="<? echo $lineColor ?>">
158 > <? printLine("Display the latest information received from a host"); ?>
159  
105 <b>Display the latest information received from a host</b>
160   <form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>">
161   <?
162  
# Line 123 | Line 177 | function showBar($title, $value, $max, $input) {
177   <input type="submit" name="submit" value="Display">
178   </form>
179  
126 <hr weight="1" color="<? echo $lineColor ?>">
127
180   <? if ($machine) {
181  
182 +       $last_modified = filemtime("$latestDirectory/$machine/$latestData");
183 +       clearstatcache();
184 +       $data_age = time() - $last_modified;
185 +
186 +       $last_modified = date("l jS F Y - g:ia", $last_modified);
187 +
188 +       if ($data_age > $warning_age) {
189 +           $warning = <<<EOT
190 +               <br>
191 +               <font color="red"><b>
192 +                   Warning:
193 +               </b></font>
194 +                   This realtime report is too old to be considered recent
195 + EOT;
196 +       }
197 +
198 + echo <<<EOT
199 +       <table border="0" bgcolor="#000066" cellpadding="3" cellspacing="1">
200 +         <tr>
201 +           <td bgcolor="#000066">
202 +             &nbsp;
203 +           </td>
204 +           <td bgcolor="#ffffcc">
205 +             <font face="arial,sans-serif" size="2">
206 +               <b>Receipt date:</b> $last_modified
207 +               $warning
208 +             </font>
209 +           </td>
210 +         </tr>
211 +       </table>
212 + EOT;
213 +
214         # Read the file.
215 <       #$input = "packet.attributes.machine_name=raptor.ukc.ac.uk,packet.memory.free=10,packet.memory.total=100,";
216 <       $input = file("$latestDirectory/$machine/$latestData");
217 <       # All we need is the first line if there is more than one line.
218 <       $input = $input[0];
215 >       if (file_exists("$latestDirectory/$machine/$latestData")) {
216 >           $input = file("$latestDirectory/$machine/$latestData");
217 >           # All we need is the first line if there is more than one line.
218 >           $input = $input[0];
219 >       }
220  
221 <       if (empty($input)) {
222 <           echo "<br><br>There was an error reading from the latest packet received.  Please notify your i-scream server administrator.";
221 >       if (!isset($input)) {
222 >           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.";
223         }
224         else {
225             # Display the data specified in the display include.
# Line 144 | Line 229 | function showBar($title, $value, $max, $input) {
229  
230   ?>
231  
232 + <? printLine(""); ?>
233  
234   <? include($bottomHTML); ?>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines