Added the snmp editor for other data uses in the form wizard snmp. TICKET: #1805
This commit is contained in:
parent
93444652b8
commit
ab64f9100c
|
@ -20,10 +20,11 @@ require_once ('include/functions_modules.php');
|
|||
require_once ('include/functions_alerts.php');
|
||||
require_once ('include/functions_reporting.php');
|
||||
require_once ('include/graphs/functions_utils.php');
|
||||
require_once("include/functions_snmp.php");
|
||||
|
||||
// Define a separator to implode/explode data
|
||||
$separator = '_.._';
|
||||
|
||||
|
||||
$idAgent = (int) get_parameter('id_agente', 0);
|
||||
$ipAgent = db_get_value('direccion', 'tagente', 'id_agente', $idAgent);
|
||||
|
||||
|
@ -63,56 +64,6 @@ if (empty($plugin)) {
|
|||
ui_print_info_message(array('message' => __('The SNMP remote plugin doesnt seem to be installed') . '. ' . __('It is necessary to use some features') . '.<br><br>' . __('Please, install the SNMP remote plugin (The name of the plugin must be snmp_remote.pl)'), 'no_close' => true));
|
||||
}
|
||||
|
||||
// Define STATIC SNMP data
|
||||
$static_snmp_descriptions = array(
|
||||
'Load-1' => 'Load Average (Last minute)',
|
||||
'Load-5' => 'Load Average (Last 5 minutes)',
|
||||
'Load-15' => 'Load Average (Last 5 minutes)',
|
||||
'memTotalSwap' => 'Total Swap Size configured for the host',
|
||||
'memAvailSwap' => 'Available Swap Space on the host',
|
||||
'memTotalReal' => 'Total Real/Physical Memory Size on the host',
|
||||
'memAvailReal' => 'Available Real/Physical Memory Space on the host',
|
||||
'memTotalFree' => 'Total Available Memory on the host',
|
||||
//'memShared' => 'Total Shared Memory',
|
||||
'memCached' => 'Total Cached Memory',
|
||||
'memBuffer' => 'Total Buffered Memory',
|
||||
'ssSwapIn' => 'Amount of memory swapped in from disk (kB/s)',
|
||||
'ssSwapOut' => 'Amount of memory swapped to disk (kB/s)',
|
||||
'ssIORawSent' => 'Number of blocks sent to a block device',
|
||||
'ssIORawReceived' => 'Number of blocks received from a block device',
|
||||
'ssRawInterrupts' => 'Number of interrupts processed',
|
||||
'ssRawContexts' => 'Number of context switches',
|
||||
'ssCpuRawUser' => 'user CPU time',
|
||||
'ssCpuRawSystem' => 'system CPU time',
|
||||
'ssCpuRawIdle' => 'idle CPU time',
|
||||
'sysUpTime' => 'system Up time');
|
||||
|
||||
$static_snmp_oids = array(
|
||||
'Load-1' => '.1.3.6.1.4.1.2021.10.1.5.1',
|
||||
'Load-5' => '.1.3.6.1.4.1.2021.10.1.5.2',
|
||||
'Load-15' => '.1.3.6.1.4.1.2021.10.1.5.3',
|
||||
'memTotalSwap' => '.1.3.6.1.4.1.2021.4.3.0',
|
||||
'memAvailSwap' => '.1.3.6.1.4.1.2021.4.4.0',
|
||||
'memTotalReal' => '.1.3.6.1.4.1.2021.4.5.0',
|
||||
'memAvailReal' => '.1.3.6.1.4.1.2021.4.6.0',
|
||||
'memTotalFree' => '.1.3.6.1.4.1.2021.4.11.0',
|
||||
//'memShared' => '.1.3.6.1.4.1.2021.4.13',
|
||||
'memCached' => '.1.3.6.1.4.1.2021.4.15.0',
|
||||
'memBuffer' => '.1.3.6.1.4.1.2021.4.14.0',
|
||||
'ssSwapIn' => '.1.3.6.1.4.1.2021.11.3.0',
|
||||
'ssSwapOut' => '.1.3.6.1.4.1.2021.11.4.0',
|
||||
'ssIORawSent' => '.1.3.6.1.4.1.2021.11.57.0',
|
||||
'ssIORawReceived' => '.1.3.6.1.4.1.2021.11.58.0',
|
||||
'ssRawInterrupts' => '.1.3.6.1.4.1.2021.11.59.0',
|
||||
'ssRawContexts' => '.1.3.6.1.4.1.2021.11.60.0',
|
||||
'ssCpuRawUser' => '.1.3.6.1.4.1.2021.11.50.0',
|
||||
'ssCpuRawSystem' => '.1.3.6.1.4.1.2021.11.52.0',
|
||||
'ssCpuRawIdle' => '.1.3.6.1.4.1.2021.11.53.0',
|
||||
'sysUpTime' => '1.3.6.1.2.1.1.3.0');
|
||||
|
||||
$static_snmp_post_process = array(
|
||||
'sysUpTime' => "0.00000011574074");
|
||||
|
||||
// Using plugin
|
||||
if (!empty($plugin)) {
|
||||
$static_snmp_descriptions['avgCpuLoad'] = 'Average of CPUs Load (%)';
|
||||
|
@ -128,6 +79,7 @@ $temperatures = array();
|
|||
|
||||
$arrow = false;
|
||||
|
||||
$snmp_translation_data = index_array(snmp_get_translation_wizard(), null, 'description');
|
||||
$other_snmp_data = array();
|
||||
|
||||
if ($snmpwalk) {
|
||||
|
@ -283,16 +235,16 @@ if ($snmpwalk) {
|
|||
// Other SNMP Data
|
||||
$arrow = true;
|
||||
|
||||
foreach ($static_snmp_oids as $key => $oid) {
|
||||
foreach ($snmp_translation_data as $oid => $temp) {
|
||||
if ($snmp_version == 3) {
|
||||
$result = false; //It is statics oids.
|
||||
}
|
||||
else {
|
||||
$result = snmpget($ip_target, $snmp_community, $oid);
|
||||
$result = @snmpget($ip_target, $snmp_community, $oid);
|
||||
}
|
||||
|
||||
if ($result != false) {
|
||||
$other_snmp_data[$key] = $static_snmp_descriptions[$key];
|
||||
$other_snmp_data[$oid] = $snmp_translation_data[$oid];
|
||||
}
|
||||
}
|
||||
if (empty($other_snmp_data)) {
|
||||
|
@ -375,10 +327,14 @@ if ($create_modules) {
|
|||
);
|
||||
|
||||
$devices_prefix_descriptions = array(
|
||||
'diskIONRead' => 'The number of bytes read from this device since boot',
|
||||
'diskIONWritten' => 'The number of bytes written to this device since boot',
|
||||
'diskIONReads' => 'The number of read accesses from this device since boot',
|
||||
'diskIONWrites' => 'The number of write accesses from this device since boot'
|
||||
'diskIONRead' =>
|
||||
__('The number of bytes read from this device since boot'),
|
||||
'diskIONWritten' =>
|
||||
__('The number of bytes written to this device since boot'),
|
||||
'diskIONReads' =>
|
||||
__('The number of read accesses from this device since boot'),
|
||||
'diskIONWrites' =>
|
||||
__('The number of write accesses from this device since boot')
|
||||
);
|
||||
|
||||
$results = array();
|
||||
|
@ -457,18 +413,17 @@ if ($create_modules) {
|
|||
|
||||
// SNMP DATA (STATIC MODULES)
|
||||
|
||||
foreach ($snmpdata as $snmpdata_name) {
|
||||
foreach ($snmpdata as $snmpdata_oid) {
|
||||
$module_values = $common_values;
|
||||
$snmp_translation = snmp_get_translation($snmpdata_oid);
|
||||
|
||||
$module_values['descripcion'] = $static_snmp_descriptions[$snmpdata_name];
|
||||
$module_values['descripcion'] =
|
||||
$snmp_translation['description'];
|
||||
$module_values['id_tipo_modulo'] = modules_get_type_id('remote_snmp');
|
||||
if (isset($static_snmp_post_process[$snmpdata_name])) {
|
||||
$module_values['post_process'] =
|
||||
$static_snmp_post_process[$snmpdata_name];
|
||||
}
|
||||
$module_values['post_process'] = $snmp_translation['post_process'];
|
||||
|
||||
//Average use of CPUs is a plugin module
|
||||
switch ($snmpdata_name) {
|
||||
switch ($snmpdata_oid) {
|
||||
case 'avgCpuLoad':
|
||||
case 'memoryUse':
|
||||
$module_values['id_modulo'] = MODULE_PLUGIN;
|
||||
|
@ -538,15 +493,16 @@ if ($create_modules) {
|
|||
unset($module_values['tcp_send']); //snmp_version
|
||||
break;
|
||||
default:
|
||||
$module_values['snmp_oid'] = $static_snmp_oids[$snmpdata_name];
|
||||
$module_values['snmp_oid'] = $snmpdata_oid;
|
||||
|
||||
$module_values['id_modulo'] = MODULE_SNMP;
|
||||
break;
|
||||
}
|
||||
|
||||
$result = modules_create_agent_module ($id_agent, io_safe_input($snmpdata_name), $module_values);
|
||||
$result = modules_create_agent_module(
|
||||
$id_agent, io_safe_input($snmp_translation['description']), $module_values);
|
||||
|
||||
$results[$result][] = $snmpdata_name;
|
||||
$results[$result][] = $snmp_translation['description'];
|
||||
}
|
||||
|
||||
// PROCESSES
|
||||
|
@ -924,7 +880,7 @@ ui_require_javascript_file ('pandora_modules');
|
|||
|
||||
var separator = '<?php echo $separator; ?>';
|
||||
|
||||
$(document).ready (function () {
|
||||
$(document).ready (function () {
|
||||
$("#walk_form").submit(function() {
|
||||
$("#oid_loading").show ();
|
||||
});
|
||||
|
@ -951,11 +907,11 @@ $(document).ready (function () {
|
|||
$("#snmp_wizard_modes").trigger('change');
|
||||
|
||||
<?php
|
||||
if (!$snmpwalk || $fail) {
|
||||
if (!$snmpwalk || $fail) {
|
||||
?>
|
||||
$('#form_interfaces').hide();
|
||||
$('#form_interfaces').hide();
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
$('.wizard_mode_devices_arrow').click(function() {
|
||||
|
@ -1045,7 +1001,7 @@ $(document).ready (function () {
|
|||
$(value).remove();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if($("#module option").length == 0) {
|
||||
$("select[name='module[]']").append($("<option></option>").val(0).html(<?php echo "'".__('None')."'"; ?>));
|
||||
}
|
||||
|
|
|
@ -306,10 +306,16 @@ if (check_acl ($config['id_user'], 0, "PM")) {
|
|||
}
|
||||
$sub["extras/pandora_diag"]["text"] = __('Diagnostic info');
|
||||
$sub["extras/pandora_diag"]["id"] = 'Diagnostic info';
|
||||
|
||||
$sub["godmode/setup/news"]["text"] = __('Site news');
|
||||
$sub["godmode/setup/news"]["id"] = 'Site news';
|
||||
|
||||
$sub["godmode/setup/file_manager"]["text"] = __('File manager');
|
||||
$sub["godmode/setup/file_manager"]["id"] = 'File manager';
|
||||
|
||||
$sub["godmode/setup/snmp_wizard"]["text"] = __('SNMP Wizard');
|
||||
$sub["godmode/setup/snmp_wizard"]["id"] = 'SNMP Wizard';
|
||||
|
||||
$menu_godmode["gextensions"]["sub"] = $sub;
|
||||
}
|
||||
|
||||
|
|
|
@ -288,7 +288,6 @@ echo "<legend>" . __('General options') . "</legend>";
|
|||
|
||||
echo "</fieldset>";
|
||||
|
||||
//enterprise_hook ('setup');
|
||||
echo '<div class="action-buttons" style="width: '.$table->width.'">';
|
||||
html_print_submit_button (__('Update'), 'update_button', false, 'class="sub upd"');
|
||||
echo '</div>';
|
||||
|
|
|
@ -0,0 +1,305 @@
|
|||
<?php
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation for version 2.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
// Load global vars
|
||||
global $config;
|
||||
|
||||
check_login ();
|
||||
|
||||
if (! check_acl ($config['id_user'], 0, "PM")) {
|
||||
db_pandora_audit("ACL Violation",
|
||||
"Trying to access Link Management");
|
||||
require ("general/noaccess.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once("include/functions_snmp.php");
|
||||
|
||||
// Header
|
||||
ui_print_page_header (__('SNMP Wizard'), "", false, "", true);
|
||||
|
||||
$table = new stdClass();
|
||||
$table->id = 'snmp';
|
||||
$table->width = '100%';
|
||||
$table->class = 'databox data';
|
||||
$table->cellpadding = 0;
|
||||
$table->cellspacing = 0;
|
||||
|
||||
$table->head = array ();
|
||||
$table->head["description"] = __('Description');
|
||||
$table->head["oid"] = __('OID');
|
||||
$table->head["post_process"] = __('Post process');
|
||||
$table->head["op"] = __('OP');
|
||||
|
||||
$table->headstyle = array ();
|
||||
$table->headstyle["description"] = "text-align: left;";
|
||||
$table->headstyle["oid"] = "text-align: left;";
|
||||
$table->headstyle["post_process"] = "text-align: right;";
|
||||
$table->headstyle["op"] = "text-align: center;";
|
||||
|
||||
$table->align = array ();
|
||||
$table->align["description"] = 'left';
|
||||
$table->align["oid"] = 'left';
|
||||
$table->align["post_process"] = 'right';
|
||||
$table->align["op"] = 'center';
|
||||
|
||||
|
||||
$table->size = array();
|
||||
$table->size["description"] = '40%';
|
||||
$table->size["oid"] = '25%';
|
||||
$table->size["post_process"] = '25%';
|
||||
$table->size["op"] = '10%';
|
||||
|
||||
$oid_translations = snmp_get_translation_wizard();
|
||||
|
||||
$table->data = array ();
|
||||
|
||||
foreach ($oid_translations as $oid => $data) {
|
||||
$row = array();
|
||||
|
||||
$row['oid'] = $oid;
|
||||
$row['description'] = $data['description'];
|
||||
$row['post_process'] = $data['post_process'];
|
||||
|
||||
if ($data['readonly']) {
|
||||
$row['op'] = '';
|
||||
}
|
||||
else {
|
||||
$row['op'] = cell_op($oid);
|
||||
}
|
||||
|
||||
|
||||
$table->data[$oid] = $row;
|
||||
}
|
||||
|
||||
|
||||
$table->data['template'] = array(
|
||||
'oid' => '',
|
||||
'description' => '',
|
||||
'post_process' => '',
|
||||
'op' => cell_op()
|
||||
);
|
||||
$table->rowstyle['template'] = 'display: none;';
|
||||
|
||||
// Form editor
|
||||
$table->data['editor'] = array(
|
||||
'oid' => html_print_input_text('oid_editor', '', '', 40, 255, true),
|
||||
'description' =>
|
||||
html_print_input_text('description_editor', '', '', 40, 255, true),
|
||||
'post_process' =>
|
||||
html_print_input_text('post_process_editor', '', '', 20, 255, true),
|
||||
'op' => '<img class="loading" src="images/spinner.gif" style="display: none;" />' .
|
||||
'<a class="button_save_snmp" href="javascript: save_translation();">' .
|
||||
html_print_image("images/save_mc.png", true, array ("title" => __('Save'))) .'</a>' .
|
||||
'<a class="button_update_snmp" href="javascript: update_snmp();" style="display: none;">' .
|
||||
html_print_image("images/update.png", true, array ("title" => __('Update'))) .
|
||||
'</a>' .
|
||||
'<a class="cancel_button_snmp" href="javascript: cancel_snmp();" style="display: none;">' .
|
||||
html_print_image("images/cancel.png", true, array ("title" => __('Cancel'))) .
|
||||
'</a>');
|
||||
|
||||
|
||||
|
||||
html_print_table($table);
|
||||
|
||||
function cell_op($oid = "") {
|
||||
return '<img class="loading" src="images/spinner.gif" style="display: none;" />' .
|
||||
'<a class="button_edit_snmp" href="javascript: edit_snmp(\'' . $oid . '\');">' .
|
||||
html_print_image("images/cog.png", true, array ("title" => __('Edit'))) .
|
||||
'</a>' .
|
||||
'<a class="delete_button_snmp" href="javascript: delete_snmp(\'' . $oid . '\');">' .
|
||||
html_print_image("images/cross.png", true, array ("title" => __('Delete'))) .
|
||||
'</a>';
|
||||
}
|
||||
?>
|
||||
|
||||
<script type="text/javascript">
|
||||
function remove_snmp_editor(oid) {
|
||||
$("#snmp-" + oid + "-editor").remove();
|
||||
}
|
||||
|
||||
function cancel_snmp(oid) {
|
||||
remove_snmp_editor(oid);
|
||||
$("#snmp-" + oid).show();
|
||||
}
|
||||
|
||||
function update_snmp_row(oid, new_oid, description, post_process) {
|
||||
add_snmp_row("#snmp-" + oid, new_oid, description, post_process);
|
||||
remove_snmp_editor(oid);
|
||||
$("#snmp-" + oid).remove();
|
||||
}
|
||||
|
||||
function update_snmp(oid) {
|
||||
var new_oid = $("#snmp-" + oid + "-editor input[name='oid_editor']").val();
|
||||
var description = $("#snmp-" + oid + "-editor input[name='description_editor']").val();
|
||||
var post_process = $("#snmp-" + oid + "-editor input[name='post_process_editor']").val();
|
||||
|
||||
params = {};
|
||||
params['page'] = "include/ajax/snmp.ajax";
|
||||
params['update_snmp_translation'] = 1;
|
||||
params['oid'] = oid;
|
||||
params['new_oid'] = new_oid;
|
||||
params['description'] = description;
|
||||
params['post_process'] = post_process;
|
||||
|
||||
$("#snmp-" + oid + " .loading").show();
|
||||
$("#snmp-" + oid + " .button_update_snmp").hide();
|
||||
|
||||
jQuery.ajax ({
|
||||
data: params,
|
||||
type: "POST",
|
||||
url: "ajax.php",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data['correct']) {
|
||||
alert("<?php echo __("Unsucessful update the snmp translation");?>");
|
||||
}
|
||||
else {
|
||||
update_snmp_row(oid, new_oid, description, post_process);
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
alert("<?php echo __("Unsucessful update the snmp translation.");?>");
|
||||
|
||||
$("#snmp-" + oid + " .loading").hide();
|
||||
$("#snmp-" + oid + " .button_update_snmp").show();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function edit_snmp(oid) {
|
||||
var description = $("#snmp-" + oid + "-description").html();
|
||||
var post_process = $("#snmp-" + oid + "-post_process").html();
|
||||
|
||||
var copy_editor = $("#snmp-editor").clone();
|
||||
|
||||
$(copy_editor).attr('id', 'snmp-' + oid + "-editor");
|
||||
$(".button_save_snmp", copy_editor).hide();
|
||||
$(".cancel_button_snmp", copy_editor).show();
|
||||
$(".cancel_button_snmp", copy_editor).attr("href", "javascript: cancel_snmp('" + oid + "');");
|
||||
$(".button_update_snmp", copy_editor).show();
|
||||
$(".button_update_snmp", copy_editor).attr("href", "javascript: update_snmp('" + oid + "');");
|
||||
$("#snmp-editor-oid input", copy_editor).val(oid);
|
||||
$("#snmp-editor-description input", copy_editor).val(description);
|
||||
$("#snmp-editor-post_process input", copy_editor).val(post_process);
|
||||
$("#snmp-" + oid).hide();
|
||||
$("#snmp-" + oid).after(copy_editor);
|
||||
}
|
||||
|
||||
function delete_snmp_row(oid) {
|
||||
$("#snmp-" + oid).remove();
|
||||
}
|
||||
|
||||
function delete_snmp(oid) {
|
||||
params = {};
|
||||
params['page'] = "include/ajax/snmp.ajax";
|
||||
params['delete_snmp_translation'] = 1;
|
||||
params['oid'] = oid;
|
||||
|
||||
$("#snmp-" + oid + " .loading").show();
|
||||
$("#snmp-" + oid + " .button_edit_snmp").hide();
|
||||
$("#snmp-" + oid + " .delete_button_snmp").hide();
|
||||
|
||||
jQuery.ajax ({
|
||||
data: params,
|
||||
type: "POST",
|
||||
url: "ajax.php",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data['correct']) {
|
||||
alert("<?php echo __("Unsucessful delete the snmp translation");?>");
|
||||
}
|
||||
else {
|
||||
delete_snmp_row(oid);
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
alert("<?php echo __("Unsucessful delete the snmp translation.");?>");
|
||||
|
||||
$("#snmp-" + oid + " .loading").hide();
|
||||
$("#snmp-" + oid + " .button_edit_snmp").show();
|
||||
$("#snmp-" + oid + " .delete_button_snmp").show();
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function add_snmp_row(position, oid, description, post_process) {
|
||||
var copy_template = $("#snmp-template").clone();
|
||||
|
||||
$(copy_template).attr('id', 'snmp-' + oid);
|
||||
|
||||
$("#snmp-template-oid", copy_template).html(oid);
|
||||
$("#snmp-template-oid", copy_template)
|
||||
.attr('id', $(copy_template).attr('id') + "-oid");
|
||||
|
||||
$("#snmp-template-description", copy_template).html(description);
|
||||
$("#snmp-template-description", copy_template)
|
||||
.attr('id', $(copy_template).attr('id') + "-description");
|
||||
|
||||
$("#snmp-template-post_process", copy_template).html(post_process);
|
||||
$("#snmp-template-post_process", copy_template)
|
||||
.attr('id', $(copy_template).attr('id') + "-post_process");
|
||||
|
||||
|
||||
$(".button_edit_snmp", copy_template)
|
||||
.attr("href", "javascript: edit_snmp('" + oid + "');");
|
||||
$(".delete_button_snmp", copy_template)
|
||||
.attr("href", "javascript: delete_snmp('" + oid + "');");
|
||||
$("#snmp-template-op", copy_template)
|
||||
.attr('id', $(copy_template).attr('id') + "-op");
|
||||
|
||||
$(copy_template).show();
|
||||
|
||||
$(position).before(copy_template);
|
||||
}
|
||||
|
||||
function save_translation() {
|
||||
var oid = $("input[name='oid_editor']").val();
|
||||
var description = $("input[name='description_editor']").val();
|
||||
var post_process = $("input[name='post_process_editor']").val();
|
||||
|
||||
$(".button_save_snmp").hide();
|
||||
$(".loading").show();
|
||||
|
||||
params = {};
|
||||
params['page'] = "include/ajax/snmp.ajax";
|
||||
params['save_snmp_translation'] = 1;
|
||||
params['oid'] = oid;
|
||||
params['description'] = description;
|
||||
params['post_process'] = post_process;
|
||||
|
||||
jQuery.ajax ({
|
||||
data: params,
|
||||
type: "POST",
|
||||
url: "ajax.php",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
if (!data['correct']) {
|
||||
alert("<?php echo __("Unsucessful save the snmp translation");?>");
|
||||
}
|
||||
else {
|
||||
add_snmp_row("#snmp-editor", oid, description, post_process);
|
||||
}
|
||||
$(".button_save_snmp").show();
|
||||
$(".loading").hide();
|
||||
},
|
||||
error: function() {
|
||||
alert("<?php echo __("Unsucessful save the snmp translation.");?>");
|
||||
|
||||
$(".button_save_snmp").show();
|
||||
$(".loading").hide();
|
||||
},
|
||||
});
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2009 Artica Soluciones Tecnologicas
|
||||
// Please see http://pandorafms.org for full contribution list
|
||||
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation for version 2.
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// Login check
|
||||
global $config;
|
||||
|
||||
require_once("include/functions_snmp.php");
|
||||
|
||||
$save_snmp_translation = (bool)get_parameter('save_snmp_translation', 0);
|
||||
$delete_snmp_translation = (bool)get_parameter('delete_snmp_translation', 0);
|
||||
$update_snmp_translation = (bool)get_parameter('update_snmp_translation', 0);
|
||||
|
||||
/* skins image checks */
|
||||
if ($save_snmp_translation) {
|
||||
$oid = get_parameter('oid', '');
|
||||
$description = get_parameter('description', '');
|
||||
$post_process = get_parameter('post_process', '');
|
||||
|
||||
$result = snmp_save_translation($oid, $description, $post_process);
|
||||
|
||||
echo json_encode(array('correct' => $result));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($delete_snmp_translation) {
|
||||
$oid = get_parameter('oid', '');
|
||||
|
||||
$result = snmp_delete_translation($oid);
|
||||
|
||||
echo json_encode(array('correct' => $result));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($update_snmp_translation) {
|
||||
$oid = get_parameter('oid', '');
|
||||
$new_oid = get_parameter('new_oid', '');
|
||||
$description = get_parameter('description', '');
|
||||
$post_process = get_parameter('post_process', '');
|
||||
|
||||
$result = snmp_update_translation($oid, $new_oid, $description, $post_process);
|
||||
|
||||
echo json_encode(array('correct' => $result));
|
||||
|
||||
return;
|
||||
}
|
||||
?>
|
|
@ -1371,9 +1371,11 @@ function index_array ($array, $index = 'id', $value = 'name') {
|
|||
if (! is_array ($array))
|
||||
return $retval;
|
||||
|
||||
foreach ($array as $element) {
|
||||
if (! isset ($element[$index]))
|
||||
continue;
|
||||
foreach ($array as $index_array => $element) {
|
||||
if (!is_null($index)) {
|
||||
if (! isset ($element[$index]))
|
||||
continue;
|
||||
}
|
||||
if ($value === false) {
|
||||
$retval[$element[$index]] = $element;
|
||||
continue;
|
||||
|
@ -1381,7 +1383,13 @@ function index_array ($array, $index = 'id', $value = 'name') {
|
|||
|
||||
if (! isset ($element[$value]))
|
||||
continue;
|
||||
$retval[$element[$index]] = $element[$value];
|
||||
|
||||
if (is_null($index)) {
|
||||
$retval[$index_array] = $element[$value];
|
||||
}
|
||||
else {
|
||||
$retval[$element[$index]] = $element[$value];
|
||||
}
|
||||
}
|
||||
|
||||
return $retval;
|
||||
|
|
|
@ -42,9 +42,13 @@ function snmp_generate_trap($snmp_host_address, $snmp_community, $snmp_oid, $snm
|
|||
else {
|
||||
$snmpwalk_bin = $config['snmptrap'];
|
||||
}
|
||||
|
||||
$command = "snmptrap -v 1 -c " . escapeshellarg($snmp_community) . " " . escapeshellarg($snmp_host_address) . " " . escapeshellarg($snmp_oid) . " "
|
||||
. escapeshellarg($snmp_agent) . " " . escapeshellarg($snmp_type) . " " . escapeshellarg($snmp_data) . " 0 2>&1";
|
||||
|
||||
$command = "snmptrap -v 1 -c " . escapeshellarg($snmp_community) .
|
||||
" " . escapeshellarg($snmp_host_address) .
|
||||
" " . escapeshellarg($snmp_oid) .
|
||||
" " . escapeshellarg($snmp_agent) .
|
||||
" " . escapeshellarg($snmp_type) .
|
||||
" " . escapeshellarg($snmp_data) . " 0 2>&1";
|
||||
|
||||
$output = null;
|
||||
exec($command, $output, $return);
|
||||
|
@ -57,4 +61,222 @@ function snmp_generate_trap($snmp_host_address, $snmp_community, $snmp_oid, $snm
|
|||
}
|
||||
}
|
||||
|
||||
?>
|
||||
function snmp_get_default_translations() {
|
||||
$return = array();
|
||||
$return['.1.3.6.1.4.1.2021.10.1.5.1'] = array(
|
||||
'description' => __('Load Average (Last minute)'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.10.1.5.2'] = array(
|
||||
'description' => __('Load Average (Last 5 minutes)'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.10.1.5.3'] = array(
|
||||
'description' => __('Load Average (Last 15 minutes)'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.4.3.0'] = array(
|
||||
'description' => __('Total Swap Size configured for the host'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.4.4.0'] = array(
|
||||
'description' => __('Available Swap Space on the host'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.4.5.0'] = array(
|
||||
'description' => __('Total Real/Physical Memory Size on the host'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.4.6.0'] = array(
|
||||
'description' => __('Available Real/Physical Memory Space on the host'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.4.11.0'] = array(
|
||||
'description' => __('Total Available Memory on the host'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.4.15.0'] = array(
|
||||
'description' => __('Total Cached Memory'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.4.14.0'] = array(
|
||||
'description' => __('Total Buffered Memory'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.11.3.0'] = array(
|
||||
'description' => __('Amount of memory swapped in from disk (kB/s)'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.11.4.0'] = array(
|
||||
'description' => __('Amount of memory swapped to disk (kB/s)'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.11.57.0'] = array(
|
||||
'description' => __('Number of blocks sent to a block device'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.11.58.0'] = array(
|
||||
'description' => __('Number of blocks received from a block device'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.11.59.0'] = array(
|
||||
'description' => __('Number of interrupts processed'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.11.60.0'] = array(
|
||||
'description' => __('Number of context switches'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.11.50.0'] = array(
|
||||
'description' => __('user CPU time'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.11.52.0'] = array(
|
||||
'description' => __('system CPU time'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['.1.3.6.1.4.1.2021.11.53.0'] = array(
|
||||
'description' => __('idle CPU time'),
|
||||
'post_process' => '1'
|
||||
);
|
||||
$return['1.3.6.1.2.1.1.3.0'] = array(
|
||||
'description' => __('system Up time'),
|
||||
'post_process' => '0.00000011574074'
|
||||
);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
function snmp_get_user_translations() {
|
||||
$row = db_get_row('tconfig', 'token', 'snmp_translations');
|
||||
|
||||
if (empty($row)) {
|
||||
db_process_sql_insert('tconfig',
|
||||
array('token' => 'snmp_translations',
|
||||
'value' => json_encode(array())));
|
||||
|
||||
$return = array();
|
||||
}
|
||||
else {
|
||||
$return = json_decode($row['value'], true);
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
function snmp_get_translation_wizard() {
|
||||
$return = array();
|
||||
|
||||
$snmp_default_translations = snmp_get_default_translations();
|
||||
$snmp_user_translations = snmp_get_user_translations();
|
||||
|
||||
foreach ($snmp_default_translations as $oid => $translation) {
|
||||
$return[$oid] = array_merge($translation, array('readonly' => 1));
|
||||
}
|
||||
|
||||
foreach ($snmp_user_translations as $oid => $translation) {
|
||||
$return[$oid] = array_merge($translation, array('readonly' => 0));
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
function snmp_save_translation($oid, $description, $post_process) {
|
||||
$row = db_get_row('tconfig', 'token', 'snmp_translations');
|
||||
|
||||
if (empty($row)) {
|
||||
db_process_sql_insert('tconfig',
|
||||
array('token' => 'snmp_translations',
|
||||
'value' => json_encode(array())));
|
||||
|
||||
$snmp_translations = array();
|
||||
}
|
||||
else {
|
||||
$snmp_translations = json_decode($row['value'], true);
|
||||
}
|
||||
|
||||
if (isset($snmp_translations[$oid])) {
|
||||
// exists the oid
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
$snmp_translations[$oid] = array(
|
||||
'description' => $description,
|
||||
'post_process' => $post_process
|
||||
);
|
||||
|
||||
return (bool)db_process_sql_update('tconfig',
|
||||
array('value' => json_encode($snmp_translations)),
|
||||
array('token' => 'snmp_translations'));
|
||||
}
|
||||
}
|
||||
|
||||
function snmp_delete_translation($oid) {
|
||||
$row = db_get_row('tconfig', 'token', 'snmp_translations');
|
||||
|
||||
if (empty($row)) {
|
||||
db_process_sql_insert('tconfig',
|
||||
array('token' => 'snmp_translations',
|
||||
'value' => json_encode(array())));
|
||||
|
||||
$snmp_translations = array();
|
||||
}
|
||||
else {
|
||||
$snmp_translations = json_decode($row['value'], true);
|
||||
}
|
||||
|
||||
if (isset($snmp_translations[$oid])) {
|
||||
unset($snmp_translations[$oid]);
|
||||
|
||||
return (bool)db_process_sql_update('tconfig',
|
||||
array('value' => json_encode($snmp_translations)),
|
||||
array('token' => 'snmp_translations'));
|
||||
}
|
||||
else {
|
||||
// exists the oid
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function snmp_get_translation($oid) {
|
||||
$snmp_translations = snmp_get_translation_wizard();
|
||||
|
||||
return $snmp_translations[$oid];
|
||||
}
|
||||
|
||||
function snmp_update_translation($oid, $new_oid, $description, $post_process) {
|
||||
$row = db_get_row('tconfig', 'token', 'snmp_translations');
|
||||
|
||||
if (empty($row)) {
|
||||
db_process_sql_insert('tconfig',
|
||||
array('token' => 'snmp_translations',
|
||||
'value' => json_encode(array())));
|
||||
|
||||
$snmp_translations = array();
|
||||
}
|
||||
else {
|
||||
$snmp_translations = json_decode($row['value'], true);
|
||||
}
|
||||
|
||||
if (isset($snmp_translations[$new_oid])) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
if (isset($snmp_translations[$oid])) {
|
||||
unset($snmp_translations[$oid]);
|
||||
|
||||
$snmp_translations[$new_oid] = array(
|
||||
'description' => $description,
|
||||
'post_process' => $post_process
|
||||
);
|
||||
|
||||
return (bool)db_process_sql_update('tconfig',
|
||||
array('value' => json_encode($snmp_translations)),
|
||||
array('token' => 'snmp_translations'));
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue