Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to zabbix 3.2 #2

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
  •  
  •  
  •  
80 changes: 58 additions & 22 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ Download

Version number of snmpbuilder with same with zabbix version for that it works.

SnmpBuilder 1.8.1
SnmpBuilder 3.2

WARNING!
This version is ported to zabbix 3.2 and IS NOT COMPATIBLE with zabbix 1.x/2.x. I wasn't tested it on zabbix 3.0, though. Mikhail Vasilyev.

Change log:

* Ported to zabbix 3.2
* Fix undefined index warnings.
* Include danrog's fix for non-numeric indexes.
* From 1.8.1, zabbix not accept specified chars in key name. So I must replace them with underscore.
Expand All @@ -34,27 +38,59 @@ I try my best to not patch Zabbix's code, but still did a little to integrate th

define('MIBS_ALL_PATH', '/home/zabbix/public_html/snmp_builder/mibs:/usr/share/snmp/mibs');

* Open include/menu.inc.php. At line 203, insert a piece of code

array('url'=>'snmp_builder.php',
'label'=>'SNMP Builder'
),

Like this:

'label'=>S_NOTIFICATIONS
),
array('url'=>'locales.php',
'label'=>S_LOCALES
),
array('url'=>'snmp_builder.php',
'label'=>'SNMP Builder'
),
array('url'=>'instal.php',
'label'=>S_INSTALLATION,
'sub_pages'=>array('setup.php','warning.php')
)
)
* Open include/menu.inc.php.

Find function zbx_construct_menu and add the following "page" in "config" section of $zbx_menu structure:
(as for the moment of this writing, it's about line 222):

[
'url' => 'snmp_builder.php',
'label' => 'SNMP Builder'
],

So the code would look like this:

[
'url' => 'hosts.php',
'label' => _('Hosts'),
'sub_pages' => [
'items.php',
'triggers.php',
'graphs.php',
'applications.php',
'tr_logform.php',
'tr_testexpr.php',
'popup_trexpr.php',
'host_discovery.php',
'disc_prototypes.php',
'trigger_prototypes.php',
'host_prototypes.php',
'httpconf.php',
'popup_httpstep.php'
]
],
[
'url' => 'snmp_builder.php',
'label' => 'SNMP Builder'
],
[
'url' => 'maintenance.php',
'label' => _('Maintenance')
],

(you actually can choose, where to put this item in menu of zabbix. My decision is to put it into "Configuration" menu
between "Hosts" and "Maintainance" entries )



* Open jsLoader.php. Add some values to $availableJScripts to make lines around line 51 look array like this:

$availableJScripts = [
// snmp_builder
'../snmp_builder/Tree.js' => '',
'../snmp_builder/snmp_builder.js' => '',
'../snmp_builder/DynTable.js' => '',
// /snmp_builder

It for integrate snmp_builder.php as a menu item under Administration tab and between Locales and Install menu. In fact, you can add it in any place.

Expand Down
92 changes: 48 additions & 44 deletions snmp_builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
?>
<?php

define('MIBS_ALL_PATH', '/home/zabbix/public_html/snmp_builder/mibs:/usr/share/snmp/mibs');
define('MIBS_ALL_PATH', '/var/www/html/zabbix/snmp_builder/mibs:/usr/share/snmp/mibs');

require_once('include/config.inc.php');

Expand Down Expand Up @@ -231,52 +231,54 @@
// From 1.8.1 zabbix not accept special char in key, :( so we must replace them with underscore
$newkey = preg_replace('/[^0-9a-zA-Z_\.]/','_',$oid[0]);

$item = array(
$item = [
'description' => $oid[0],
'name' => $oid[0],
'key_' => $newkey,
'hostid' => $templateid,
'delay' => $oid[4],
'history' => 90,
'history' => 90*3600,
'status' => ITEM_STATUS_ACTIVE,
'type' => ITEM_TYPE_SNMPV2C,
'snmp_community'=> $community,
'snmp_oid' => $oid_num,
'value_type' => $value_type,
'trapper_hosts' => null,
'snmp_port' => null,
// 'trapper_hosts' => null,
//// // 'snmp_port' => null,
'units' => $oid[3],
'multiplier' => $multiplier,
'delta' => $delta,
'snmpv3_securityname' => null,
/* 'snmpv3_securityname' => null,
'snmpv3_securitylevel' => null,
'snmpv3_authpassphrase' => null,
'snmpv3_privpassphrase' => null,
'snmpv3_privpassphrase' => null, */
'formula' => $oid[5],
'trends' => null,
/* 'trends' => null,
'logtimefmt' => null,
'valuemapid' => null,
'valuemapid' => null,*/
'delay_flex' => null,
'authtype' => null,
/* 'authtype' => null,
'username' => null,
'password' => null,
'publickey' => null,
'privatekey' => null,
'params' => null,
'ipmi_sensor' => null,
'data_type' => $data_type);
'ipmi_sensor' => null, */
'data_type' => $data_type];

array_push($items, $item);

}


foreach ($items as $item)
{
# foreach ($items as $item)
# {
DBstart();
$itemid = false;
$itemid = add_item($item);
$itemid = API::Item()->create($items);

$result = DBend($itemid);
}
# }



Expand Down Expand Up @@ -322,7 +324,7 @@
}

$form->addItem(array('MIB:'.SPACE,$cmbMibs,SPACE));

$form->addItem((new CTag('br')));
// server textbox
$ipbServer = new CTextBox('server_ip',$server_ip);
$form->addItem(array('Server:'.SPACE,$ipbServer,SPACE));
Expand All @@ -331,7 +333,9 @@
$tbCommunity = new CTextBox('community',$community);
$form->addItem(array('Community:'.SPACE,$tbCommunity ,SPACE));

$snmp_wdgt->addHeader('SNMP Builder', $form);
#$snmp_wdgt->addHeader('SNMP Builder', $form);
$snmp_wdgt->setTitle('SNMP Builder');
$snmp_wdgt->setControls($form);

//Body
$outer_table = new CTable();
Expand All @@ -344,23 +348,20 @@
//Left panel
$left_tab = new CTable();
//Oid tree
$oid_tree_w = new CWidget();
$oid_tree_w->setClass('header');
$oid_tree_w->addHeader("Oid Tree");
$oid_tree_w = new CColHeader("Oid Tree");

$oid_tree_div = new CDiv();
$oid_tree_div->setAttribute("id","oidtree");

$oid_tree_container = new CDiv($oid_tree_div);
$oid_tree_container->addStyle("overflow: auto; background-color: rgb(255, 255, 255); height: 300px; width: 300px;");
$oid_tree_container->addClass(ZBX_STYLE_TREEVIEW);
$oid_tree_container->addStyle("overflow: auto; height: 300px; width: 300px;");

$oid_tree_w->addItem($oid_tree_container);
$left_tab->addRow($oid_tree_w);

//Oid description
$oid_info_w = new CWidget();
$oid_info_w->setClass('header');
$oid_info_w->addHeader("Information");
$oid_info_w = new CColHeader("Information");

$oid_info_div = new CDiv();
$oid_info_div->setAttribute("id","oidinfo");
Expand All @@ -371,21 +372,18 @@
//Right panel
$right_tab = new CTable();
//Oidview
$oid_view_w = new CWidget();
$oid_view_w->setClass('header');
$oid_view_w->addHeader(array("Oid View - click to view as table:",new CCheckBox('viewtype','no','onViewType()',1)));
$oid_view_w = (new CColHeader(
( (new CCheckBox('viewtype'))->onClick('onViewType()') ) ));
// $oid_view_w->addHeader(array("Oid View - click to view as table:",));


$oid_view_div = new CDiv();
$oid_view_div->setAttribute("id","oidview");
$oid_view_div ->addStyle("overflow: auto; max-height: 250px; width: 800px");
$oid_view_w->addItem($oid_view_div);
$right_tab->addRow($oid_view_w);

//Itemlist
$item_list_w = new CWidget();
$item_list_w->setClass('header');
$item_list_w->addHeader("Item List");
$item_list_w = new CColHeader('Item List');

$item_list_div = new CDiv();
$item_list_div->setAttribute("id","itemlist");
Expand All @@ -394,16 +392,13 @@
$right_tab->addRow($item_list_w);

//Action srow
$action_w= new CWidget();
$action_w->setClass('header');

$action_w->addHeader(array(new CButton('save','Save','javascript: onSaveItems()'), SPACE, new CButton('clear','Clear List','javascript: onClearItems()')));
//$action_div = new CDiv();
//$action_w->addItem($action_div);
$right_tab->addRow($action_w);


$action_w= (new CButton('save',_('Save')))->addStyle("margin: 10px;")->onClick('onSaveItems()');
$action_c= (new CButton('clear',_('Clear')))->addStyle("margin: 10px;")->onClick('onClearItems()');

$right_tab->addRow([[],[$action_w,$action_c ]]);

// Left panel

$td_l = new CCol($left_tab);
$td_l->setAttribute('valign','top');
$td_l->setAttribute('width','300px');
Expand Down Expand Up @@ -561,11 +556,20 @@ function get_templates()
'nopermissions' => 1
);
$template = array();
foreach (CTemplate::get($options) as $key => $value)
$templateget = API::Template()->get([
'output' => ['templateid', 'name'],
'preservekeys' => true
]);

# foreach (CTemplate::get($options) as $key => $value)
# {
# array_push($template, array('key' => $key, 'host' => $value['host']));
# }
#
foreach ($templateget as $key => $value)
{
array_push($template, array('key' => $key, 'host' => $value['host']));
array_push($template, array('key' => $key, 'host' => $value['name']));
}

return $template;

}
Expand Down
4 changes: 2 additions & 2 deletions snmp_builder/DynTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ DynTable.prototype = {

createTable : function(){
this.container.update();
this.container.insert({ top: '<table class= "tableinfo" cellspacing="1" cellpadding="3" id="dyntable-'+this.element+'"></table>' });
this.container.insert({ top: '<table class= "list-table" cellspacing="1" cellpadding="3" id="dyntable-'+this.element+'"></table>' });
this.table = $('dyntable-'+this.element);
this.tbody = new Element('tbody');
this.table.insert({top: this.tbody});
Expand Down Expand Up @@ -163,4 +163,4 @@ DynTable.prototype = {
this.tbody.insert({ bottom: row });
}
}
};
};
12 changes: 8 additions & 4 deletions snmp_builder/Tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -3392,9 +3392,13 @@ TafelTreeBaseBranch.prototype = {
if (this.objDrag) {
this.objDrag.destroy();
}
Droppables.remove(this.txt);
// Droppables.remove(this.txt);
for (var i = 0; i < this.children.length; i++) {
try {
this.children[i].removeDragDrop();
} catch (err) {
console.log(err.message);
};
}
},

Expand Down Expand Up @@ -3978,9 +3982,9 @@ TafelTreeBaseBranch.prototype = {
Element.addClassName(this.txt, this.tree.classDrag);
}
}
if (this.struct.acceptdrop) {
/* if (this.struct.acceptdrop) {
Droppables.add(this.txt, {hoverclass: this.tree.classDragOver, onDrop: this.setDrop.bindAsEventListener(this)});
}
}*/
if (this.struct.tooltip) {
Event.observe(event, 'mouseover', this.evt_showTooltip.bindAsEventListener(this), false);
Event.observe(event, 'mouseout', this.evt_hideTooltip.bindAsEventListener(this), false);
Expand Down Expand Up @@ -5871,4 +5875,4 @@ function TafelTreeInitBase (ev) {
}
};

Event.observe(window, 'load', TafelTreeInitBase, false);
Event.observe(window, 'load', TafelTreeInitBase, false);
Loading