line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FusionInventory::Agent::Task::Inventory::BSD::Uptime; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
84104125
|
use strict; |
|
1
|
|
|
|
|
13
|
|
|
1
|
|
|
|
|
75
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
91
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
515
|
use FusionInventory::Agent::Tools; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
475
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub isEnabled { |
9
|
0
|
|
|
0
|
0
|
|
return canRun('sysctl'); |
10
|
|
|
|
|
|
|
} |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub doInventory { |
13
|
0
|
|
|
0
|
0
|
|
my (%params) = @_; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my $inventory = $params{inventory}; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
my $arch = getFirstLine(command => 'uname -m'); |
18
|
0
|
|
|
|
|
|
my $uptime = _getUptime(command => 'sysctl -n kern.boottime'); |
19
|
0
|
|
|
|
|
|
$inventory->setHardware({ |
20
|
|
|
|
|
|
|
DESCRIPTION => "$arch/$uptime" |
21
|
|
|
|
|
|
|
}); |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _getUptime { |
25
|
0
|
|
|
0
|
|
|
my $line = getFirstLine(@_); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# the output of 'sysctl -n kern.boottime' differs between BSD flavours |
28
|
0
|
0
|
|
|
|
|
my $boottime = |
|
|
0
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$line =~ /^(\d+)/ ? $1 : # OpenBSD format |
30
|
|
|
|
|
|
|
$line =~ /sec = (\d+)/ ? $1 : # FreeBSD format |
31
|
|
|
|
|
|
|
undef; |
32
|
0
|
0
|
|
|
|
|
return unless $boottime; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
my $uptime = $boottime - time(); |
35
|
0
|
|
|
|
|
|
return getFormatedGMTTime($uptime); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
1; |