From af0bf1fd5b9cb1316d6e34bff0ed41061e14443d Mon Sep 17 00:00:00 2001 From: Ivan Kohler Date: Wed, 9 Dec 2015 16:55:58 -0800 Subject: deal when Net::MAC::Vendor-lookup doesn't return an arrayref, RT#39384 --- httemplate/view/elements/svc_Common.html | 4 ++-- httemplate/view/elements/svc_devices.html | 3 ++- httemplate/view/elements/svc_radius_usage.html | 7 +++++-- 3 files changed, 9 insertions(+), 5 deletions(-) (limited to 'httemplate') diff --git a/httemplate/view/elements/svc_Common.html b/httemplate/view/elements/svc_Common.html index d7a1dcf30..296c27bbc 100644 --- a/httemplate/view/elements/svc_Common.html +++ b/httemplate/view/elements/svc_Common.html @@ -283,8 +283,8 @@ my $format_field = sub { } elsif ( $type eq 'checkbox' ) { $value = $value eq 'Y' ? emt('Yes') : emt('No'); } elsif ( $type =~ /(input-)?mac_addr/ and $value =~ /\w/) { - my $vendor = Net::MAC::Vendor::lookup($value)->[0]; - $value .= " ($vendor)" if $vendor; + my $vendor = Net::MAC::Vendor::lookup($value); + $value .= ' ('. $vendor->[0]. ')' if $vendor; $value = $m->scomp('/elements/mac_addr.html', $value); } diff --git a/httemplate/view/elements/svc_devices.html b/httemplate/view/elements/svc_devices.html index 899e6aa47..3d4e1bbc5 100644 --- a/httemplate/view/elements/svc_devices.html +++ b/httemplate/view/elements/svc_devices.html @@ -63,7 +63,8 @@ <% $td %><% $device->part_device->devicename |h %> % } <% $td %><% $device->mac_addr_pretty %> - (<% (Net::MAC::Vendor::lookup($device->mac_addr_formatted('U',':')))->[0] %>) +% my $vendor = Net::MAC::Vendor::lookup($device->mac_addr_formatted('U',':')); + (<% $vendor ? $vendor->[0] : '' %>) <% $td %><% $export_links %> <% $td %>( diff --git a/httemplate/view/elements/svc_radius_usage.html b/httemplate/view/elements/svc_radius_usage.html index 471969175..56198524c 100644 --- a/httemplate/view/elements/svc_radius_usage.html +++ b/httemplate/view/elements/svc_radius_usage.html @@ -27,8 +27,11 @@ % ) / 1073741824; % % my $last_mac = $svc->attribute_last_sqlradacct( 'CallingStationId' ); -% if ( $last_mac =~ /^\s*(([\dA-F]{2}[\-:]){5}[\dA-F]{2})/i ) { -% $last_mac .= ' ('. (Net::MAC::Vendor::lookup($1))->[0]. ')'; +% if ( $last_mac =~ /^\s*(([\dA-F]{2}[\-:]){5}[\dA-F]{2})/i +% && my $vendor = Net::MAC::Vendor::lookup($1) +% ) +% { +% $last_mac .= ' ('. $vendor->[0]. ')'; % } -- cgit v1.2.1 From 3a02a1bce4190ce0d94883709e0a6c362bcb0af3 Mon Sep 17 00:00:00 2001 From: Jonathan Prykop Date: Wed, 9 Dec 2015 23:39:52 -0600 Subject: RT#39115: View SNMP info on svc_broadband service --- .../edit/elements/part_export/broadband_snmp.html | 8 +- .../elements/part_export/broadband_snmp_get.html | 77 +++++++++ httemplate/elements/broadband_snmp_get-dialog.html | 68 ++++++++ httemplate/elements/select-mib-popup.html | 186 --------------------- httemplate/misc/select-mib-popup.html | 186 +++++++++++++++++++++ httemplate/misc/xmlhttp-broadband_snmp_get.cgi | 35 ++++ httemplate/view/svc_broadband.cgi | 1 + 7 files changed, 372 insertions(+), 189 deletions(-) create mode 100644 httemplate/edit/elements/part_export/broadband_snmp_get.html create mode 100644 httemplate/elements/broadband_snmp_get-dialog.html delete mode 100644 httemplate/elements/select-mib-popup.html create mode 100644 httemplate/misc/select-mib-popup.html create mode 100644 httemplate/misc/xmlhttp-broadband_snmp_get.cgi (limited to 'httemplate') diff --git a/httemplate/edit/elements/part_export/broadband_snmp.html b/httemplate/edit/elements/part_export/broadband_snmp.html index ebb765dee..b4d57edd5 100644 --- a/httemplate/edit/elements/part_export/broadband_snmp.html +++ b/httemplate/edit/elements/part_export/broadband_snmp.html @@ -11,7 +11,7 @@ <& /elements/tr-input-text.html, label => 'Community', field => 'community', - curr_value => $part_export->option('community'), + curr_value => $part_export->option('community') || $opt{'export_info'}->{'options'}->{'community'}->{'default'}, &> <& /elements/tr-checkbox.html, label => 'Send IP address changes to new address', @@ -30,7 +30,7 @@ function open_select_mib(obj) { nd(1); // if there's already one open, close it var rownum = obj.rownum; var curr_oid = obj.form.elements['oid' + rownum].value || ''; - var url = '<%$fsurl%>/elements/select-mib-popup.html?' + + var url = '<%$fsurl%>misc/select-mib-popup.html?' + 'callback=receive_mib;' + 'arg=' + rownum + ';curr_value=' + curr_oid; @@ -45,8 +45,10 @@ function open_select_mib(obj) { function receive_mib(obj, rownum) { //console.log(JSON.stringify(obj)); // we don't really need the numeric OID or any of the other properties - document.getElementById('oid'+rownum).value = obj.fullname; + var oidfield = document.getElementById('oid'+rownum); + oidfield.value = obj.fullname; document.getElementById('datatype'+rownum).value = obj.type; + oidfield.onchange(); //should be same as datatype, only need to run one } diff --git a/httemplate/edit/elements/part_export/broadband_snmp_get.html b/httemplate/edit/elements/part_export/broadband_snmp_get.html new file mode 100644 index 000000000..8b8717c29 --- /dev/null +++ b/httemplate/edit/elements/part_export/broadband_snmp_get.html @@ -0,0 +1,77 @@ +<%doc> +Quite a bit of false laziness with edit/elements/part_export/broadband_snmp.html + +<& head.html, %opt &> + +<& /elements/tr-select.html, + label => 'SNMP version', + field => 'snmp_version', + options => [ '1', '2c' ], + curr_value => $part_export->option('version') +&> +<& /elements/tr-input-text.html, + label => 'Community', + field => 'snmp_community', + curr_value => $part_export->option('community') || $opt{'export_info'}->{'options'}->{'snmp_community'}->{'default'}, +&> +<& /elements/tr-input-text.html, + label => 'Timeout (seconds)', + field => 'snmp_timeout', + curr_value => $part_export->option('timeout') || $opt{'export_info'}->{'options'}->{'snmp_timeout'}->{'default'}, +&> + + + + + + + + +<& /elements/auto-table.html, + template_row => 'broadband_snmp_get_template', + fieldorder => ['oid'], + data => \@data, + table => 'snmp', +&> + +<& foot.html, %opt &> +<%init> +my %opt = @_; + +my $part_export = $opt{part_export} || FS::part_export->new; + +my @oids = split("\n", $part_export->option('snmp_oid')); + +my @data; +while (@oids) { + my @thisrow = (shift(@oids)); + push @data, \@thisrow if grep length($_), @thisrow; +} + +my $popup_name = 'popup-'.time."-$$-".rand() * 2**32; + diff --git a/httemplate/elements/broadband_snmp_get-dialog.html b/httemplate/elements/broadband_snmp_get-dialog.html new file mode 100644 index 000000000..61bb9c763 --- /dev/null +++ b/httemplate/elements/broadband_snmp_get-dialog.html @@ -0,0 +1,68 @@ +<%doc> +Adds a link to display snmp statistics based on broadband_snmp_get export config. +Performs necessary checks such that, if no such exports are configured for the passed +service, returns blank space (ie may be safely invoked even if no exports are configured.) + + <& '/elements/broadband_snmp_get-dialog.html', svc => $svc &> + + +% if (@snmp) { +<& '/elements/xmlhttp.html', + 'url' => $fsurl.'misc/xmlhttp-broadband_snmp_get.cgi', + 'subs' => [ 'broadband_snmp_get_request' ] + &> + + + +(snmp) + + +% } #if @snmp +<%init> +my(%opt) = @_; +my @snmp = $opt{'svc'}->cust_svc->part_svc->part_export('broadband_snmp_get'); +my $svcnum = $opt{'svc'}->svcnum; + diff --git a/httemplate/elements/select-mib-popup.html b/httemplate/elements/select-mib-popup.html deleted file mode 100644 index f95ce2b97..000000000 --- a/httemplate/elements/select-mib-popup.html +++ /dev/null @@ -1,186 +0,0 @@ -<& /elements/header-popup.html &> - -
Object ID
+ + +
- - - - - - - - - - - - - - - - - - - - - - - -
Module:
Object:
- -
Module:
Data type:
- -
-<& /elements/xmlhttp.html, - url => $p.'misc/xmlhttp-mib-browse.html', - subs => [qw( search get_module_list )], -&> - -<& /elements/footer.html &> -<%init> -my $callback = 'alert("(no callback defined)" + selected_mib.stringify)'; -$cgi->param('callback') =~ /^(\w+)$/; -if ( $1 ) { - # construct the JS function call expresssion - $callback = 'window.parent.' . $1 . '(selected_mib'; - foreach ($cgi->param('arg')) { - # pass-through arguments - /^(\w+)$/ or next; - $callback .= ",'$1'"; - } - $callback .= ')'; -} - - diff --git a/httemplate/misc/select-mib-popup.html b/httemplate/misc/select-mib-popup.html new file mode 100644 index 000000000..f95ce2b97 --- /dev/null +++ b/httemplate/misc/select-mib-popup.html @@ -0,0 +1,186 @@ +<& /elements/header-popup.html &> + + + + + + + + + + + + + + + + + + + + + + + + + +
Module:
Object:
+ +
Module:
Data type:
+ +
+<& /elements/xmlhttp.html, + url => $p.'misc/xmlhttp-mib-browse.html', + subs => [qw( search get_module_list )], +&> + +<& /elements/footer.html &> +<%init> +my $callback = 'alert("(no callback defined)" + selected_mib.stringify)'; +$cgi->param('callback') =~ /^(\w+)$/; +if ( $1 ) { + # construct the JS function call expresssion + $callback = 'window.parent.' . $1 . '(selected_mib'; + foreach ($cgi->param('arg')) { + # pass-through arguments + /^(\w+)$/ or next; + $callback .= ",'$1'"; + } + $callback .= ')'; +} + + diff --git a/httemplate/misc/xmlhttp-broadband_snmp_get.cgi b/httemplate/misc/xmlhttp-broadband_snmp_get.cgi new file mode 100644 index 000000000..a6f926722 --- /dev/null +++ b/httemplate/misc/xmlhttp-broadband_snmp_get.cgi @@ -0,0 +1,35 @@ +<%doc> +Requires arg $svcnum. Returns JSON-encoded realtime snmp results +for configured broadband_snmp_get exports. + +<% encode_json(\@result) %>\ +<%init> + +# access/agent permissions lifted from /view/elements/svc_Common.html + +die "access denied" + unless $FS::CurrentUser::CurrentUser->access_right('View customer services'); + +my %arg = $cgi->param('arg'); +my $svc = qsearchs({ + 'select' => 'svc_broadband.*', + 'table' => 'svc_broadband', + 'addl_from' => ' LEFT JOIN cust_svc USING ( svcnum ) '. + ' LEFT JOIN cust_pkg USING ( pkgnum ) '. + ' LEFT JOIN cust_main USING ( custnum ) ', + 'hashref' => { 'svcnum' => $arg{'svcnum'} }, + 'extra_sql' => ' AND '. $FS::CurrentUser::CurrentUser->agentnums_sql( + 'null_right' => 'View/link unlinked services' + ), +}) or die "Unknown svcnum ".$arg{'svcnum'}." in svc_broadband table\n"; + +my @part_export = $svc->cust_svc->part_svc->part_export('broadband_snmp_get'); + +my @result; +foreach my $part_export (@part_export) { + push @result, $part_export->snmp_results($svc); +} + + + + diff --git a/httemplate/view/svc_broadband.cgi b/httemplate/view/svc_broadband.cgi index 4935a1096..bc272e844 100644 --- a/httemplate/view/svc_broadband.cgi +++ b/httemplate/view/svc_broadband.cgi @@ -72,6 +72,7 @@ sub ip_addr { my $out = $ip_addr; $out .= ' (' . include('/elements/popup_link-ping.html', ip => $ip_addr) . ')' if $ip_addr; + $out .= include('/elements/broadband_snmp_get-dialog.html', svc => $svc); if ($svc->cust_svc->part_svc->part_export('cacti')) { $out .= ' (