From 29467692120ccbd5a216aec723b9f69aaa7db452 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Thu, 13 Jun 2013 14:27:18 +0000 Subject: [PATCH] 2013-06-13 Miguel de Dios * include/functions_snmp.php: changed the PHP function to execute command and now get the error string or return true if it runs fine. * godmode/snmpconsole/snmp_trap_generator.php: show the error when fail to call snmptrap, and show error when occurs. Fixes: #2270 MERGED FROM THE BRANCH PANDORA_4.0 git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@8318 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 12 ++++++++++++ .../godmode/snmpconsole/snmp_trap_generator.php | 17 ++++++++++++----- pandora_console/include/functions_snmp.php | 12 +++++++++++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 319c988332..6f18f25ee7 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,15 @@ +2013-06-13 Miguel de Dios + + * include/functions_snmp.php: changed the PHP function to execute + command and now get the error string or return true if it runs fine. + + * godmode/snmpconsole/snmp_trap_generator.php: show the error when + fail to call snmptrap, and show error when occurs. + + Fixes: #2270 + + MERGED FROM THE BRANCH PANDORA_4.0 + 2013-06-13 Mario Pulido * images/help/actions.png, diff --git a/pandora_console/godmode/snmpconsole/snmp_trap_generator.php b/pandora_console/godmode/snmpconsole/snmp_trap_generator.php index 53c7d108ee..4d36d17a6c 100644 --- a/pandora_console/godmode/snmpconsole/snmp_trap_generator.php +++ b/pandora_console/godmode/snmpconsole/snmp_trap_generator.php @@ -36,18 +36,25 @@ $generate_trap = (bool) get_parameter ("generate_trap", 0); ui_print_page_header (__("SNMP Trap generator"), "images/op_snmp.png", false, "", false); -if($generate_trap) { +if ($generate_trap) { $result = true; - if($snmp_host_address != '' && $snmp_community != '' && $snmp_oid != '' && $snmp_agent != '' && $snmp_value != '' && $snmp_type != -1) { - snmp_generate_trap($snmp_host_address, $snmp_community, $snmp_oid, $snmp_agent, $snmp_value, $snmp_type); + $error = ''; + if ($snmp_host_address != '' && $snmp_community != '' && $snmp_oid != '' && $snmp_agent != '' && $snmp_value != '' && $snmp_type != -1) { + $result = snmp_generate_trap($snmp_host_address, $snmp_community, $snmp_oid, $snmp_agent, $snmp_value, $snmp_type); + + if ($result !== true) { + $error = $result; + $result = false; + } } else { + $error = __('Empty parameters'); $result = false; } ui_print_result_message ($result, - __('Successfully generated'), - __('Could not be generated')); + __('Successfully generated'), + sprintf(__('Could not be generated: %s'), $error)); } $traps_generator = '
'; diff --git a/pandora_console/include/functions_snmp.php b/pandora_console/include/functions_snmp.php index 0fb1a818a6..257b126959 100644 --- a/pandora_console/include/functions_snmp.php +++ b/pandora_console/include/functions_snmp.php @@ -25,7 +25,17 @@ * @param string Snmp especific OID. */ function snmp_generate_trap($snmp_host_address, $snmp_community, $snmp_oid, $snmp_agent, $snmp_data, $snmp_type) { - system("snmptrap -v 1 -c $snmp_community $snmp_host_address $snmp_oid $snmp_agent $snmp_type $snmp_data 0"); + $command = "snmptrap -v 1 -c $snmp_community $snmp_host_address $snmp_oid $snmp_agent $snmp_type $snmp_data 0 2>&1"; + + $output = null; + exec($command, $output, $return); + + if ($return == 0) { + return true; + } + else { + return implode(' ', $output); + } } ?>