+ Add mode time in snmp for windows

This commit is contained in:
Quentin Garnier 2014-08-25 17:05:57 +02:00
parent 109b2c5b12
commit 37f0b95e65
2 changed files with 26 additions and 12 deletions

View File

@ -47,17 +47,18 @@ sub new {
$self->{version} = '0.1'; $self->{version} = '0.1';
%{$self->{modes}} = ( %{$self->{modes}} = (
'cpu' => 'snmp_standard::mode::cpu', 'cpu' => 'snmp_standard::mode::cpu',
'list-interfaces' => 'snmp_standard::mode::listinterfaces', 'list-interfaces' => 'snmp_standard::mode::listinterfaces',
'list-storages' => 'snmp_standard::mode::liststorages', 'list-storages' => 'snmp_standard::mode::liststorages',
'memory' => 'os::windows::snmp::mode::memory', 'memory' => 'os::windows::snmp::mode::memory',
'packet-errors' => 'snmp_standard::mode::packeterrors', 'packet-errors' => 'snmp_standard::mode::packeterrors',
'processcount' => 'snmp_standard::mode::processcount', 'processcount' => 'snmp_standard::mode::processcount',
'service' => 'os::windows::snmp::mode::service', 'service' => 'os::windows::snmp::mode::service',
'storage' => 'snmp_standard::mode::storage', 'storage' => 'snmp_standard::mode::storage',
'swap' => 'os::windows::snmp::mode::swap', 'swap' => 'os::windows::snmp::mode::swap',
'traffic' => 'snmp_standard::mode::traffic', 'time' => 'snmp_standard::mode::ntp',
'uptime' => 'snmp_standard::mode::uptime', 'traffic' => 'snmp_standard::mode::traffic',
'uptime' => 'snmp_standard::mode::uptime',
); );
return $self; return $self;

View File

@ -54,6 +54,7 @@ sub new {
"ntp-port:s" => { name => 'ntp_port', default => 123 }, "ntp-port:s" => { name => 'ntp_port', default => 123 },
"warning:s" => { name => 'warning' }, "warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' }, "critical:s" => { name => 'critical' },
"timezone:s" => { name => 'timezone' },
}); });
return $self; return $self;
} }
@ -109,6 +110,13 @@ sub run {
} }
my @remote_date = unpack 'n C6 a C2', $result->{$oid_hrSystemDate}; my @remote_date = unpack 'n C6 a C2', $result->{$oid_hrSystemDate};
my $timezone = 'UTC';
if (defined($self->{option_results}->{timezone})) {
$timezone = $self->{option_results}->{timezone};
} elsif (defined($remote_date[9])) {
$timezone = sprintf("%s%02d%02d", $remote_date[7], $remote_date[8], $remote_date[9]); # format +0630
}
my $dt = DateTime->new( my $dt = DateTime->new(
year => $remote_date[0], year => $remote_date[0],
month => $remote_date[1], month => $remote_date[1],
@ -116,7 +124,7 @@ sub run {
hour => $remote_date[3], hour => $remote_date[3],
minute => $remote_date[4], minute => $remote_date[4],
second => $remote_date[5], second => $remote_date[5],
time_zone => sprintf("%s%02d%02d", $remote_date[7], $remote_date[8], $remote_date[9]) , # format +0630 time_zone => $timezone,
); );
$distant_time = $dt->epoch; $distant_time = $dt->epoch;
@ -165,6 +173,11 @@ Set the ntp hostname (if not set, localtime is used).
Set the ntp port (Default: 123). Set the ntp port (Default: 123).
=item B<--timezone>
Set the timezone of distant server. For Windows, you need to set it.
Can use format: 'Europe/London' or '+0100'.
=back =back
=cut =cut