3 /**************************************************************************
4 ** (c) Copyright 2003, Andromeda Technology & Automation
5 ** This is free software; you can redistribute it and/or modify it under the
6 ** terms of the GNU General Public License, see the file COPYING.
7 ***************************************************************************
8 ** MODULE INFORMATION *
9 ***********************
10 ** FILE NAME : objects.php
11 ** SYSTEM NAME : Gnucomo - Gnu Computer Monitoring
12 ** VERSION NUMBER : $Revision: 1.7 $
14 ** DESCRIPTION : Objects Administration page.
15 ** Input parameters: action (POST) : empty, 'Create'
16 ** objname (POST) : name of the object to create or remove
21 ***************************************************************************
22 ** ADMINISTRATIVE INFORMATION *
23 ********************************
24 ** ORIGINAL AUTHOR : Arjen Baart - arjen@andromeda.nl
25 ** CREATION DATE : Dec 04, 2002
26 ** LAST UPDATE : Feb 14, 2003
28 **************************************************************************/
30 /*****************************
32 Revision 1.7 2003-07-15 11:02:25 arjen
33 Use the new object_statistics table.
35 Revision 1.6 2003/02/21 08:46:58 arjen
36 Improved the table layout.
38 Revision 1.5 2003/02/13 09:01:29 arjen
39 All web interface pages use the page class.
41 Revision 1.4 2003/02/13 08:48:23 arjen
42 Added log, notification and parameter counters to the 'object' table.
43 Counting these things at the time a user interface needs them is
44 too slow. Other programs, like gcm_daemon en gcm_input should prepare
45 these counters for quick retrieval.
47 Revision 1.3 2003/02/10 15:42:24 arjen
48 Show the total number of Log entries, parameters and notifications
50 Revision 1.2 2003/02/05 09:48:14 arjen
51 Added display and handling of notifications
53 ******************************/
55 // RCSID = "$Id: objects.php,v 1.7 2003-07-15 11:02:25 arjen Exp $";
57 ini_set('include_path', '.:./classes:../phpclasses');
59 require_once('page.class.php');
61 function clientscripts()
65 <script language='JavaScript'>
67 function CheckCreate(f)
69 if (f.objectname.value == "")
71 alert("You must supply a name");
77 function CheckRemove(f)
79 var message = "Are you sure you want to remove object ";
80 message += f.objectname.value;
83 return confirm(message);
91 class object_page extends page
94 var $nr_parameters, $removed_parameters;
95 var $nr_notifications, $closed_notifications;
98 function GatherStatistics($objectid)
100 // Gather statistics on parameters
102 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
103 . $objectid . "' AS BIGINT) AND statname='parameters'");
104 $stat = pg_fetch_object($r, 0);
105 $this->nr_parameters = $stat->statvalue;
107 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
108 . $objectid . "' AS BIGINT) AND statname='removed_parameters'");
109 $stat = pg_fetch_object($r, 0);
110 $this->removed_parameters = $stat->statvalue;
112 // Gather statistics on notifications
114 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
115 . $objectid . "' AS BIGINT) AND statname='notifications'");
116 $stat = pg_fetch_object($r, 0);
117 $this->nr_notifications = $stat->statvalue;
119 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
120 . $objectid . "' AS BIGINT) AND statname='closed_notifications'");
121 $stat = pg_fetch_object($r, 0);
122 $this->closed_notifications = $stat->statvalue;
124 // Gather statistics on log entries
126 $r = pg_exec ($this->database, "SELECT statvalue FROM object_statistics WHERE objectid=CAST('"
127 . $objectid . "' AS BIGINT) AND statname='logs'");
128 $stat = pg_fetch_object($r, 0);
129 $this->nr_logs = $stat->statvalue;
137 echo "<h1>Objects Administration</h1><hr>";
139 if (isset($_POST['action']) && $_POST['action'] == 'Create' && !empty($_POST['objectname']))
141 pg_exec($this->database, "INSERT INTO object (objectname, log_count, parameter_count, notification_count)
142 VALUES ('" . $_POST['objectname'] . "', '0', '0', '0')");
145 if (isset($_POST['action']) && $_POST['action'] == 'Remove' && !empty($_POST['objectname']))
147 pg_exec($this->database, "DELETE FROM object WHERE objectname='" . $_POST['objectname'] . "'");
150 $res = pg_exec($this->database, "SELECT objectid,objectname, log_count, notification_count
151 FROM object ORDER BY objectname");
155 <tr><th>Object</th><th>Log entries</th>
156 <th>Parameters</th><th>Notifications</th>
162 //The counters are set to zero
164 $count_notifications = 0;
165 $closed_notifications = 0;
166 $count_parameters = 0;
167 $removed_parameters = 0;
169 while ($obj < pg_numrows($res))
171 $u = pg_fetch_object($res, $obj);
173 $this->GatherStatistics($u->objectid);
175 $count_parameters += $this->nr_parameters;
176 $removed_parameters += $this->removed_parameters;
177 $count_logs = $count_logs + $this->nr_logs;
179 //$nr_notifications = $u->notification_count;
180 $count_notifications += $this->nr_notifications;
181 $closed_notifications += $this->closed_notifications;
183 <tr><td><center><img src='server.png'><br>
184 <b><?php echo $u->objectname ?></b></center>
185 </td><td class='number'>
186 <?php echo "<a href='log.php?oid=$u->objectid'> $this->nr_logs </a>" ?>
187 </td><td class='number'>
188 <?php echo "<a href='parameter.php?oid=$u->objectid'>" . $this->nr_parameters
189 . " (" . $this->removed_parameters . " removed)</a>" ?>
190 </td><td class='number'>
191 <?php echo "<a href='notification.php?oid=$u->objectid'>" . $this->nr_notifications . " (" . $this->closed_notifications . " closed)</a>" ?>
193 <form action='objects.php' method='post' onSubmit='return CheckRemove(this)'>
194 <input type='hidden' name='objectname' value='<?php echo $u->objectname ?>'>
195 <input type='submit' name='action' value='Remove'>
203 echo "<tr><td><strong><B><br><br>TOTALS</B></strong></td>";
204 echo "<td class='number'>$count_logs</td>";
205 echo "<td class='number'>$count_parameters ($removed_parameters removed)</td>";
206 echo "<td class='number'>$count_notifications ($closed_notifications closed)</td></tr>";
211 <h2>Create new object:</h2>
214 <form action='objects.php' method='post' onSubmit='return CheckCreate(this)'>
215 Object's name (FQDN): <input name='objectname' type='text'>
217 <input type='submit' name='action' value='Create'>
225 $obj_page = new object_page("Gnucomo Objects Administration");
227 $obj_page->Showpage();