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

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

Copyt trusty code

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