Open-AudIT
https://www.open-audit.org/phpBB3/

Uptime
https://www.open-audit.org/phpBB3/viewtopic.php?f=20&t=5731
Page 1 of 1

Author:  jpa [ Wed Jun 15, 2011 3:10 am ]
Post subject:  Uptime

As an exercise I added system uptime auditing to OAv2 Beta 1.1 with the updated audit script. The WMI code I used only works on WinXP/Server2003 and above. As this was an exercise it could be totally wrong. Hopefully not.

Code:
--- OAv2/code_igniter/system/application/models/m_system.php   Thu Jan 15 01:14:12 1970
+++ OAv2/code_igniter/system/application/models/m_system.php   Thu Jan 15 01:14:12 1970
@@ -309,6 +309,7 @@
                   man_type       = 'system',
                   pc_num_processor    = ?,
                   pc_date_os_installation = ?,
+                  uptime = ?,
                   timestamp = ?
                WHERE
                   system.system_id = ?";
@@ -336,7 +337,8 @@
                   "$input_each->system_serial",
                   str_replace(" ", "_", mb_strtolower($input_each->system_os_short_name)),
                   "$input_each->system_pc_num_processor",
-                  "$input_each->system_pc_date_os_installation",
+                  "$input_each->system_pc_date_os_installation",
+                  "$input_each->system_uptime",             
                   "$input_each->system_timestamp",
                   "$details->system_id");
                $query = $this->db->query($sql, $data);
@@ -364,6 +366,7 @@
                   pc_memory = ?,
                   pc_num_processor = ?,
                   pc_date_os_installation = ?,
+                  uptime = ?,
                   timestamp = ?
                WHERE
                   system.system_id = ?";
@@ -382,6 +385,7 @@
                      "$input_each->system_pc_memory",
                      "$input_each->system_pc_num_processor",
                      "$input_each->system_pc_date_os_installation",
+                     "$input_each->system_uptime",
                      "$input_each->system_timestamp",
                      "$details->system_id");
                $query = $this->db->query($sql, $data);
@@ -422,6 +426,7 @@
                man_type       = 'system',
                pc_num_processor    = ?,
                pc_date_os_installation = ?,
+               uptime = ?,
                first_timestamp    = ?,
                timestamp       = ?";
             $data = array($system_key,
@@ -451,6 +456,7 @@
                   "$input_each->system_os_name",
                   "$input_each->system_pc_num_processor",
                   "$input_each->system_pc_date_os_installation",
+                  "$input_each->system_uptime",
                   "$input_each->system_timestamp",
                   "$input_each->system_timestamp");
             $query = $this->db->query($sql, $data);
--- OAv2/code_igniter/system/application/views/lang/en.inc   Thu Jan 15 01:14:12 1970
+++ OAv2/code_igniter/system/application/views/lang/en.inc   Thu Jan 15 01:14:12 1970
@@ -933,6 +933,7 @@
 $GLOBALS["lang"]["Partitions (Database Servers)"]="Partitions (Database Servers)";
 $GLOBALS["lang"]["Shares (Database Servers)"]="Shares (Database Servers)";
 $GLOBALS["lang"]["Most Recent Audit"]="Most Recent Audit";
+$GLOBALS["lang"]["Uptime"]="Uptime";
 $GLOBALS["lang"]["Alerts (Windows Systems)"]="Alerts (Windows Systems)";
 $GLOBALS["lang"]["Audit Dates (Windows Systems)"]="Audit Dates (Windows Systems)";
 $GLOBALS["lang"]["System Locations (Windows Systems)"]="System Locations (Windows Systems)";
@@ -1044,4 +1045,5 @@
 $GLOBALS["lang"]["Deleted"]="Deleted";
 $GLOBALS["lang"]["Summary - pssbs"]="Summary - pssbs";
 $GLOBALS["lang"]["Acrobat (All Devices)"]="Acrobat (All Devices)";
+$GLOBALS["lang"]["%d d %d h %d m %d s"]="%d d %d h %d m %d s";
 ?>
\ No newline at end of file
--- OAv2/code_igniter/system/application/views/theme-tango/v_system_display.php   Thu Jan 15 01:14:12 1970
+++ OAv2/code_igniter/system/application/views/theme-tango/v_system_display.php   Thu Jan 15 01:14:12 1970
@@ -123,6 +123,7 @@
                   <p><label for="man_description"><?php echo __('Description')?>: </label><span id="man_description" <?php echo $edit?>><?php echo print_something($key->man_description)?></span></p>
                   <p><label for="man_criticality_select"><?php echo __('Criticality')?>: </label><span id="man_criticality_select" style="color:blue;"><span onclick="display_criticality();"><?php echo print_something($key->man_criticality)?></span></span></p>
                   <p><label for="timestamp"><?php echo __('Most Recent Audit')?>: </label><span id="timestamp"><?php echo print_something($key->timestamp)?></span></p>
+                  <p><label for="uptime"><?php echo __('Uptime')?>: </label><span id="uptime"><?php echo print_uptime($key->uptime)?></span></p>
                   <?php if ($key->man_os_group == 'Windows') { ?>
                      <p><label for="os_version"><?php echo __('Windows Version')?>: </label><span id="os_version"><?php echo print_something($key->os_version)?></span></p>
                   <?php } elseif ($key->man_os_group == 'Linux') { ?>
@@ -2291,6 +2292,22 @@
    {
       return '-';
    } else {
+      return $string;
+   }
+}
+
+function print_uptime($seconds)
+{
+   if ($seconds == 0)
+   {
+      return '-';
+   } else {
+      $days = intval( $seconds/86400 );
+      $hours = intval ( ($seconds/3600) - ($days*24));
+      $minutes = intval( ($seconds - (($days*86400)+ ($hours*3600)))/60);
+      $seconds = $seconds - ( ($days*86400)+($hours*3600)+($minutes * 60));
+      $format = __('%d d %d h %d m %d s');
+      $string = sprintf($format, $days, $hours, $minutes, $seconds);
       return $string;
    }
 }
--- OAv2/other/audit_windows.vbs   Thu Jan 15 01:14:12 1970
+++ OAv2/other/audit_windows.vbs   Thu Jan 15 01:14:12 1970
@@ -253,6 +253,11 @@
    system_form_factor = form_factor(Join(objItem.ChassisTypes, ","))
 next
 
+Set colItems = objWMIService.ExecQuery("Select * From Win32_PerfFormattedData_PerfOS_System",,48)
+For Each objItem in colItems
+    system_uptime = objItem.SystemUpTime
+Next
+
 result = "<?xml version=""1.0"" encoding=""ISO-8859-1""?>" & vbcrlf
 'result = "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbcrlf
 result = result & "<system>" & vbcrlf
@@ -275,6 +280,7 @@
 result = result & "      <system_pc_memory>" & escape_xml(system_pc_memory) & "</system_pc_memory>" & vbcrlf
 result = result & "      <system_pc_num_processor>" & escape_xml(system_pc_num_processor) & "</system_pc_num_processor>" & vbcrlf
 result = result & "      <system_pc_date_os_installation>" & escape_xml(system_pc_date_os_installation) & "</system_pc_date_os_installation>" & vbcrlf
+result = result & "      <system_uptime>" & escape_xml(system_uptime) & "</system_uptime>" & vbcrlf
 result = result & "      <man_org_id>" & escape_xml(org_id) & "</man_org_id>" & vbcrlf
 result = result & "   </sys>" & vbcrlf
 
--- OAv2/other/OAv2_mysql.sql   Thu Jan 15 01:14:12 1970
+++ OAv2/other/OAv2_mysql.sql   Thu Jan 15 01:14:12 1970
@@ -1612,6 +1612,7 @@
   `pc_memory` int(10) NOT NULL default '0',
   `pc_num_processor` int(10) NOT NULL default '0',
   `pc_date_os_installation` date NOT NULL default '0000-00-00',
+  `uptime` int(10) NOT NULL default '0',
   `printer_port_name` varchar(50) NOT NULL default '',
   `printer_shared` varchar(50) NOT NULL default '',
   `printer_shared_name` varchar(50) NOT NULL default '',


Page 1 of 1 All times are UTC + 10 hours
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/