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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
package FS::part_export::broadband_snmp_get;
use strict;
use vars qw(%info $DEBUG);
use base 'FS::part_export';
use SNMP;
use Tie::IxHash;
tie my %snmp_version, 'Tie::IxHash',
v1 => '1',
v2c => '2c'
# v3 unimplemented
;
tie my %options, 'Tie::IxHash',
'snmp_version' => {
label=>'SNMP version',
type => 'select',
options => [ keys %snmp_version ],
},
'snmp_community' => { 'label'=>'Community', 'default'=>'public' },
'snmp_timeout' => { label=>'Timeout (seconds)', 'default'=>1 },
'snmp_oid' => { label=>'Object ID', multiple=>1 },
;
%info = (
'svc' => 'svc_broadband',
'desc' => 'Enable interface display of realtime SNMP get requests to service IP address',
'config_element' => '/edit/elements/part_export/broadband_snmp_get.html',
'options' => \%options,
'no_machine' => 1,
'notes' => <<'END',
Display broadband service status information via SNMP. Timeout is
per object, and should be small enough for realtime use. This export takes no action
during provisioning itself; it is expected that snmp will be separately
configured on the service machine.
END
);
sub export_insert { ''; }
sub export_replace { ''; }
sub export_delete { ''; }
sub export_suspend { ''; }
sub export_unsuspend { ''; }
=pod
=head1 NAME
FS::part_export::broadband_snmp_get
=head1 SYNOPSIS
Configuration for realtime snmp requests to svc_broadband IP address
=head1 METHODS
=cut
=over 4
=item snmp_results SVC
Request statistics from SVC ip address. Returns an array of hashes with keys
objectID
label
value
error - error when attempting to load this object
=cut
sub snmp_results {
my ($self, $svc) = @_;
my $host = $svc->ip_addr;
my $comm = $self->option('snmp_community');
my $vers = $self->option('snmp_version');
my $time = ($self->option('snmp_timeout') || 1) * 1000;
my @oids = split("\n", $self->option('snmp_oid'));
my %connect = (
'DestHost' => $host,
'Community' => $comm,
'Version' => $vers,
'Timeout' => $time,
);
my $snmp = new SNMP::Session(%connect);
return { 'error' => 'Error creating SNMP session' } unless $snmp;
return { 'error' => $snmp->{'ErrorStr'} } if $snmp->{'ErrorStr'};
my @out;
foreach my $oid (@oids) {
$oid = $SNMP::MIB{$oid}->{'objectID'} if $SNMP::MIB{$oid};
my $value = $snmp->get($oid.'.0');
if ($snmp->{'ErrorStr'}) {
push @out, { 'error' => $snmp->{'ErrorStr'} };
next;
}
my %result = map { $_ => $SNMP::MIB{$oid}{$_} } qw( objectID label value );
$result{'value'} = $value;
push @out, \%result;
}
return @out;
}
=back
=cut
1;
|