185 |
|
|
186 |
|
} |
187 |
|
|
188 |
< |
# sub to get system uptime. |
188 |
> |
# sub to get system uptime in seconds. |
189 |
|
sub include_uptime() { |
190 |
|
|
191 |
|
# debug stuff, all the different cases |
209 |
|
my($uptime) = `$uptimebin`; |
210 |
|
|
211 |
|
# work out the days, hours, and minutes |
212 |
< |
if ($uptime =~ /hr/) { |
213 |
< |
# two possible cases here |
214 |
< |
if($uptime =~ /day/) { |
215 |
< |
# 0 minutes |
216 |
< |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; |
217 |
< |
$uptime = "$1:$2:0"; |
212 |
> |
|
213 |
> |
if ($uptime =~ /day.*,\s+([0-9]+):([0-9]+)/) { |
214 |
> |
# normal |
215 |
> |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+):([0-9]+)/; |
216 |
> |
$uptime = "$1:$2:$3"; |
217 |
> |
} |
218 |
> |
else { |
219 |
> |
if ($uptime =~ /day/) { |
220 |
> |
if ($uptime =~ /hr/) { |
221 |
> |
# 0 minutes |
222 |
> |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; |
223 |
> |
$uptime = "$1:$2:0"; |
224 |
> |
} |
225 |
> |
elsif ($uptime =~ /min/) { |
226 |
> |
# 0 hours |
227 |
> |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; |
228 |
> |
$uptime = "$1:0:$2"; |
229 |
> |
} |
230 |
> |
else { |
231 |
> |
# 0 hours and 0 mins |
232 |
> |
$uptime =~ /up\s+([0-9]+)/; |
233 |
> |
$uptime = "$1:0:0"; |
234 |
> |
} |
235 |
|
} |
236 |
< |
else { |
236 |
> |
elsif ($uptime =~ /hr/) { |
237 |
|
# 0 days and 0 minutes |
238 |
|
$uptime =~ /up\s+([0-9]+)\s+/; |
239 |
|
$uptime = "0:$1:0"; |
240 |
|
} |
241 |
< |
} |
225 |
< |
elsif ($uptime =~ /min/) { |
226 |
< |
# two possible cases here |
227 |
< |
if($uptime =~ /day/) { |
228 |
< |
# 0 hours |
229 |
< |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+)\s+.*,/; |
230 |
< |
$uptime = "$1:0:$2"; |
231 |
< |
} |
232 |
< |
else { |
241 |
> |
elsif ($uptime =~ /min/) { |
242 |
|
# 0 days and 0 hours |
243 |
|
$uptime =~ /up\s+([0-9]+)\s+/; |
244 |
|
$uptime = "0:0:$1"; |
245 |
|
} |
237 |
– |
} |
238 |
– |
elsif ($uptime =~ /day/) { |
239 |
– |
if ($uptime =~ /day.*,\s+([0-9]+):([0-9]+)/) { |
240 |
– |
# normal |
241 |
– |
$uptime =~ /up\s+([0-9]+)\s+.*,\s+([0-9]+):([0-9]+)/; |
242 |
– |
$uptime = "$1:$2:$3"; |
243 |
– |
} |
246 |
|
else { |
247 |
< |
# 0 hours and 0 mins |
248 |
< |
$uptime =~ /up\s+([0-9]+)/; |
249 |
< |
$uptime = "$1:0:0"; |
247 |
> |
# 0 days |
248 |
> |
$uptime =~ /up\s+([0-9]+):([0-9]+)/; |
249 |
> |
$uptime = "0:$1:$2"; |
250 |
|
} |
251 |
|
} |
250 |
– |
else { |
251 |
– |
# 0 days |
252 |
– |
$uptime =~ /up\s+([0-9]+):([0-9]+)/; |
253 |
– |
$uptime = "0:$1:$2"; |
254 |
– |
} |
252 |
|
|
253 |
< |
# turn into minutes |
257 |
< |
|
253 |
> |
# turn into seconds |
254 |
|
$uptime =~ /([0-9]+):([0-9]+):([0-9]+)/; |
255 |
< |
$uptime = $3 + ($2 + $1*24)*60; |
256 |
< |
|
255 |
> |
$uptime = ($3+($2+($1*24))*60)*60; |
256 |
> |
|
257 |
> |
# print the value out |
258 |
|
&print_pair("unknown", "packet.os.uptime", $uptime); |
259 |
|
|
260 |
|
} |