diff options
author | Jonathan Prykop <jonathan@freeside.biz> | 2015-12-09 23:39:52 -0600 |
---|---|---|
committer | Jonathan Prykop <jonathan@freeside.biz> | 2015-12-09 23:39:52 -0600 |
commit | 3a02a1bce4190ce0d94883709e0a6c362bcb0af3 (patch) | |
tree | 055961d63c00774effa2890a5ce20d8965418fdd /httemplate/misc | |
parent | af0bf1fd5b9cb1316d6e34bff0ed41061e14443d (diff) |
RT#39115: View SNMP info on svc_broadband service
Diffstat (limited to 'httemplate/misc')
-rw-r--r-- | httemplate/misc/select-mib-popup.html | 186 | ||||
-rw-r--r-- | httemplate/misc/xmlhttp-broadband_snmp_get.cgi | 35 |
2 files changed, 221 insertions, 0 deletions
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 &> +<DIV STYLE="visibility: hidden; position: absolute" ID="measurebox"></DIV> +<TABLE WIDTH="100%"> +<TR> + <TD WIDTH="30%" ALIGN="right">Module:</TD> + <TD><SELECT ID="select_module"></SELECT></TD> +</TR> +<TR> + <TD ALIGN="right">Object:</TD> + <TD><INPUT TYPE="text" NAME="path" ID="input_path" SIZE=50 WIDTH="100%"></TD> +</TR> +<TR> + <TD COLSPAN=2> + <SELECT STYLE="width:100%" SIZE=12 ID="select_path"></SELECT> + </TD> +</TR> +<TR> + <TH ALIGN="center" COLSPAN=2 ID="mib_objectID"></TH> +</TR> +<TR> + <TD ALIGN="right">Module: </TD><TD ID="mib_moduleID"></TD> +</TR> +<TR> + <TD ALIGN="right">Data type: </TD><TD ID="mib_type"></TD> +</TR> +<TR> + <TH COLSPAN=2> + <BUTTON ID="submit_button" onclick="submit()" DISABLED=1>Continue</BUTTON> + </TH> +</TR> +</TABLE> +<& /elements/xmlhttp.html, + url => $p.'misc/xmlhttp-mib-browse.html', + subs => [qw( search get_module_list )], +&> +<SCRIPT TYPE="text/javascript"> + +var selected_mib; + +function show_info(state) { + document.getElementById('mib_objectID').style.display = + document.getElementById('mib_moduleID').style.display = + document.getElementById('mib_type').style.display = + state ? '' : 'none'; +} + +function clear_list() { + var select_path = document.getElementById('select_path'); + select_path.options.length = 0; +} + +var measurebox = document.getElementById('measurebox'); +function add_item(value) { + var select_path = document.getElementById('select_path'); + var input_path = document.getElementById('input_path'); + var opt = document.createElement('option'); + var v = value; + if ( v.match(/-$/) ) { + opt.className = 'leaf'; + v = v.substring(0, v.length - 1); + } + var optvalue = v; // may not be the name we display + // shorten these if they don't fit in the box + if ( v.length > 30 ) { // unless they're already really short + measurebox.innerHTML = v; + while ( measurebox.clientWidth > select_path.clientWidth - 10 + && v.match(/^\..*\./) ) { + v = v.replace(/^\.[^\.]+/, ''); + measurebox.innerHTML = v; + } + if ( optvalue != v ) { + v = '...' + v; + } + } + opt.value = optvalue; + opt.text = v; + opt.selected = (input_path.value == v); + select_path.add(opt, null); +} + +var timerID = 0; + +function populate(json_result) { + var result = JSON.parse(json_result); + clear_list(); + for (var x in result['choices']) { + opt = document.createElement('option'); + add_item(result['choices'][x]); + } + if ( result['objectID'] ) { + selected_mib = result; + show_info(true); + // show details on the selected node + document.getElementById('mib_objectID').innerHTML = result.objectID; + document.getElementById('mib_moduleID').innerHTML = result.moduleID; + document.getElementById('mib_type').innerHTML = result.type; + document.getElementById('submit_button').disabled = !result.type; + } else { + selected_mib = undefined; + show_info(false); + } +} + +function populate_modules(json_result) { + var result = JSON.parse(json_result); + var select_module = document.getElementById('select_module'); + var opt = document.createElement('option'); + opt.value = 'ANY'; + opt.text = '(any)'; + select_module.add(opt, null); + for (var x in result['modules']) { + opt = document.createElement('option'); + opt.value = opt.text = result['modules'][x]; + select_module.add(opt, null); + } +} + +function dispatch_search() { + // called from the interval timer + var search_string = document.getElementById('select_module').value + ':' + + document.getElementById('input_path').value; + + search(search_string, populate); +} + +function delayed_search() { + // onkeyup handler for the text input + // 500ms after the user stops typing, send the search request + if (timerID != 0) { + clearTimeout(timerID); + } + timerID = setTimeout(dispatch_search, 500); +} + +function handle_choose_object() { + // onchange handler for the selector + // when the user picks an option, set the text input to that, and then + // search for it as though it was entered + var input_path = document.getElementById('input_path'); + input_path.value = this.value; + dispatch_search(); +} + +function handle_choose_module() { + input_path.value = ''; // just to avoid confusion + delayed_search(); +} + +function submit() { +% if ( $callback ) { + <% $callback %>; + parent.nd(1); // close popup +% } else { + alert(document.getElementById('input_path').value); +% } +} + +var input_path = document.getElementById('input_path'); +input_path.onkeyup = delayed_search; +var select_path = document.getElementById('select_path'); +select_path.onchange = handle_choose_object; +var select_module = document.getElementById('select_module'); +select_module.onchange = handle_choose_module; +% if ( $cgi->param('curr_value') ) { +input_path.value = <% $cgi->param('curr_value') |js_string %>; +% } +dispatch_search(); +get_module_list('', populate_modules); + +</SCRIPT> +<& /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 .= ')'; +} + +</%init> 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. +</%doc> +<% 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); +} + +</%init> + + |