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 },
24 'snmp_oid_name' => { label=>'Object Name', multiple=>1 },
28 'svc' => 'svc_broadband',
29 'desc' => 'Enable interface display of realtime SNMP get requests to service IP address',
30 'config_element' => '/edit/elements/part_export/broadband_snmp_get.html',
31 'options' => \%options,
34 Display broadband service status information via SNMP. Timeout is
35 per object, and should be small enough for realtime use. This export takes no action
36 during provisioning itself; it is expected that snmp will be separately
37 configured on the service machine.
41 sub export_insert { ''; }
42 sub export_replace { ''; }
43 sub export_delete { ''; }
44 sub export_suspend { ''; }
45 sub export_unsuspend { ''; }
51 FS::part_export::broadband_snmp_get
55 Configuration for realtime snmp requests to svc_broadband IP address
63 =item snmp_results SVC
65 Request statistics from SVC ip address. Returns an array of hashrefs with keys
69 objectID - dotted decimal fully qualified OID
71 label - leaf textual identifier (e.g., 'sysDescr')
73 values - arrayref of arrayrefs describing values, [<obj>, <iid>, <val>, <type>]
78 my ($self, $svc) = @_;
79 my $host = $svc->ip_addr;
80 my $comm = $self->option('snmp_community');
81 my $vers = $self->option('snmp_version');
82 my $time = ($self->option('snmp_timeout') || 1) * 1000000;
83 my @oids = split("\n", $self->option('snmp_oid'));
84 my @oidnames = split("\n", $self->option('snmp_oid_name'));
91 my $snmp = new SNMP::Session(%connect);
92 return { 'error' => 'Error creating SNMP session' } unless $snmp;
93 return { 'error' => $snmp->{'ErrorStr'} } if $snmp->{'ErrorStr'};
95 for (my $i=0; $i <= $#oids; $i++) {
97 my $oidname = $oidnames[$i];
98 $oid = $SNMP::MIB{$oid}->{'objectID'} if $SNMP::MIB{$oid};
101 my $varbind = new SNMP::Varbind [$oid];
102 my $max = 1000; #sanity check
103 while ($max > 0 and defined($snmp->getnext($varbind))) {
104 last if $snmp->{'ErrorStr'};
105 last unless $SNMP::MIB{$varbind->[0]}; # does this happen?
106 my $nextoid = $SNMP::MIB{$varbind->[0]}->{'objectID'};
107 last unless $nextoid =~ /^$oid/;
109 push @values, [ @$varbind ];
112 # not clear on what max-repeaters (25) does, plucked value from example code
113 # but based on testing, it isn't capping number of returned values
114 my ($values) = $snmp->bulkwalk(0,25,$oid);
115 @values = @$values if $values;
117 if ($snmp->{'ErrorStr'} || !@values) {
118 push @out, { 'error' => $snmp->{'ErrorStr'} || 'No values retrieved' };
121 my %result = map { $_ => $SNMP::MIB{$oid}{$_} } qw( objectID label );
122 $result{'name'} = $oidname;
123 # unbless @values, for ease of JSON encoding
124 $result{'values'} = [];
125 foreach my $value (@values) {
126 push @{$result{'values'}}, [ map { $_ } @$value ];