source: ocsinventory-agent/trunk/fuentes/lib/Ocsinventory/Agent/Backend/OS/BSD/Uptime.pm @ 468

Last change on this file since 468 was 468, checked in by mabarracus, 4 years ago

Copyt trusty code

File size: 860 bytes
Line 
1package Ocsinventory::Agent::Backend::OS::BSD::Uptime;
2use strict;
3
4sub check {
5  my $boottime = `sysctl -n kern.boottime 2>/dev/null`;
6  return 1 if $boottime;
7  return;
8}
9
10sub run {
11  my $params = shift;
12  my $common = $params->{common};
13 
14  chomp (my $boottime = `sysctl -n kern.boottime`);
15  $boottime = $1 if $boottime =~ /sec\s*=\s*(\d+)/;
16  chomp (my $currenttime = `date +%s`);
17  my $uptime = $currenttime - $boottime;
18
19  # Uptime conversion
20  my ($UYEAR, $UMONTH , $UDAY, $UHOUR, $UMIN, $USEC) = (gmtime ($uptime))[5,4,3,2,1,0];
21
22  # Write in ISO format
23  $uptime=sprintf "%02d-%02d-%02d %02d:%02d:%02d", ($UYEAR-70), $UMONTH, ($UDAY-1), $UHOUR, $UMIN, $USEC;
24 
25  chomp(my $DeviceType =`uname -m`);
26#  TODO$h->{'CONTENT'}{'HARDWARE'}{'DESCRIPTION'} = [ "$DeviceType/$uptime" ];
27  $common->setHardware({ DESCRIPTION => "$DeviceType/$uptime" });
28}
29
301
Note: See TracBrowser for help on using the repository browser.