1 package FS::part_export::broadband_snmp_get;
4 use vars qw(%info $DEBUG);
5 use base 'FS::part_export';
9 tie my %snmp_version, 'Tie::IxHash',
15 tie my %options, 'Tie::IxHash',
17 label=>'SNMP version',
19 options => [ keys %snmp_version ],
21 'snmp_community' => { 'label'=>'Community', 'default'=>'public' },
22 'snmp_timeout' => { label=>'Timeout (seconds)', 'default'=>1 },
23 'snmp_oid' => { label=>'Object ID', multiple=>1 },
27 'svc' => 'svc_broadband',
28 'desc' => 'Enable interface display of realtime SNMP get requests to service IP address',
29 'config_element' => '/edit/elements/part_export/broadband_snmp_get.html',
30 'options' => \%options,
33 Display broadband service status information via SNMP. Timeout is
34 per object, and should be small enough for realtime use. This export takes no action
35 during provisioning itself; it is expected that snmp will be separately
36 configured on the service machine.
40 sub export_insert { ''; }
41 sub export_replace { ''; }
42 sub export_delete { ''; }
43 sub export_suspend { ''; }
44 sub export_unsuspend { ''; }
50 FS::part_export::broadband_snmp_get
54 Configuration for realtime snmp requests to svc_broadband IP address
62 =item snmp_results SVC
64 Request statistics from SVC ip address. Returns an array of hashrefs with keys
68 objectID - dotted decimal fully qualified OID
70 label - leaf textual identifier (e.g., 'sysDescr')
72 values - arrayref of arrayrefs describing values, [<obj>, <iid>, <val>, <type>]
77 my ($self, $svc) = @_;
78 my $host = $svc->ip_addr;
79 my $comm = $self->option('snmp_community');
80 my $vers = $self->option('snmp_version');
81 my $time = ($self->option('snmp_timeout') || 1) * 1000000;
82 my @oids = split("\n", $self->option('snmp_oid'));
89 my $snmp = new SNMP::Session(%connect);
90 return { 'error' => 'Error creating SNMP session' } unless $snmp;
91 return { 'error' => $snmp->{'ErrorStr'} } if $snmp->{'ErrorStr'};
93 foreach my $oid (@oids) {
94 $oid = $SNMP::MIB{$oid}->{'objectID'} if $SNMP::MIB{$oid};
97 my $varbind = new SNMP::Varbind [$oid];
98 my $max = 1000; #sanity check
99 while ($max > 0 and defined($snmp->getnext($varbind))) {
100 last if $snmp->{'ErrorStr'};
101 last unless $SNMP::MIB{$varbind->[0]}; # does this happen?
102 my $nextoid = $SNMP::MIB{$varbind->[0]}->{'objectID'};
103 last unless $nextoid =~ /^$oid/;
105 push @values, [ @$varbind ];
108 # not clear on what max-repeaters (25) does, plucked value from example code
109 # but based on testing, it isn't capping number of returned values
110 my ($values) = $snmp->bulkwalk(0,25,$oid);
111 @values = @$values if $values;
113 if ($snmp->{'ErrorStr'} || !@values) {
114 push @out, { 'error' => $snmp->{'ErrorStr'} || 'No values retrieved' };
117 my %result = map { $_ => $SNMP::MIB{$oid}{$_} } qw( objectID label );
118 # unbless @values, for ease of JSON encoding
119 $result{'values'} = [];
120 foreach my $value (@values) {
121 push @{$result{'values'}}, [ map { $_ } @$value ];