File: Uptime.pm

package info (click to toggle)
ocsinventory-agent 2%3A2.10.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,424 kB
  • sloc: perl: 26,492; xml: 773; objc: 528; sh: 386; ansic: 333; makefile: 12
file content (29 lines) | stat: -rw-r--r-- 872 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package Ocsinventory::Agent::Backend::OS::MacOS::Uptime;
use strict;

sub check {
    my $boottime = `sysctl -n kern.boottime 2>/dev/null`; # straight from the BSD module ;-)
    return 1 if $boottime;
    return;
}

sub run {
    my $params = shift;
    my $common = $params->{common};

    # stolen code from bsd.
    chomp (my $boottime = `sysctl -n kern.boottime`);
    $boottime = $1 if $boottime =~ /sec\s*=\s*(\d+)/;
    chomp (my $currenttime = `date +%s`);
    my $uptime = $currenttime - $boottime;

    # Uptime conversion
    my ($UYEAR, $UMONTH , $UDAY, $UHOUR, $UMIN, $USEC) = (gmtime ($uptime))[5,4,3,2,1,0];

    # Write in ISO format
    $uptime=sprintf "%02d-%02d-%02d %02d:%02d:%02d", ($UYEAR-70), $UMONTH, ($UDAY-1), $UHOUR, $UMIN, $USEC;

    chomp(my $DeviceType =`uname -m`);
    $common->setHardware({ DESCRIPTION => "$DeviceType/$uptime" });
}
1;