Skip to content

Commit

Permalink
net-mgmt/zabbix-agent: add support for UserParameters
Browse files Browse the repository at this point in the history
  • Loading branch information
fraenki committed Nov 18, 2018
1 parent 6b6c0d0 commit 6764f7e
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,35 @@ class SettingsController extends ApiMutableModelControllerBase
{
static protected $internalModelName = 'zabbixagent';
static protected $internalModelClass = '\OPNsense\ZabbixAgent\ZabbixAgent';

public function searchUserparametersAction()
{
return $this->searchBase('userparameters.userparameter', array("enabled", "key", "command"));
}

public function getUserparameterAction($uuid = null)
{
$this->sessionClose();
return $this->getBase('userparameter', 'userparameters.userparameter', $uuid);
}

public function addUserparameterAction()
{
return $this->addBase('userparameter', 'userparameters.userparameter');
}

public function delUserparameterAction($uuid)
{
return $this->delBase('userparameters.userparameter', $uuid);
}

public function setUserparameterAction($uuid)
{
return $this->setBase('userparameter', 'userparameters.userparameter', $uuid);
}

public function toggleUserparameterAction($uuid)
{
return $this->toggleBase('userparameters.userparameter', $uuid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public function indexAction()
{
// include form definitions
$this->view->settingsForm = $this->getForm("settings");
// link userparameter dialog
$this->view->formDialogUserparameter = $this->getForm("dialogUserparameter");
// pick the template to serve
$this->view->pick('OPNsense/ZabbixAgent/index');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<form>
<field>
<id>userparameter.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
<help>Enable this userparameter.</help>
</field>
<field>
<id>userparameter.key</id>
<label>Key</label>
<type>text</type>
<help>Enter a unique item key of your choice.</help>
</field>
<field>
<id>userparameter.command</id>
<label>Command</label>
<type>text</type>
<help>Command to be executed to evaluate value of the key.</help>
</field>
<field>
<id>userparameter.acceptParams</id>
<label>Accept Parameters</label>
<type>checkbox</type>
<help>Flexible user parameters accept parameters with the key. This way a flexible user parameter can be the basis for creating several items.</help>
</field>
</form>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<form>
<activetab>zabbixagent-settings-main</activetab>
<tab id="zabbixagent-settings-main" description="Main Settings">
<field>
<id>zabbixagent.settings.main.enabled</id>
Expand Down Expand Up @@ -125,5 +126,4 @@
<help><![CDATA[Enable logging of executed shell commands as warnings. Make sure to set the Debug Level accordingly.]]></help>
</field>
</tab>
<activetab>zabbixagent-settings-main</activetab>
</form>
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<model>
<mount>//OPNsense/ZabbixAgent</mount>
<version>1.1.0</version>
<description>
Enterprise-class open source distributed monitoring agent
</description>
<version>1.2.0</version>
<description>Enterprise-class open source distributed monitoring agent</description>
<items>
<!-- local settings that should NOT be synced to another node -->
<local>
Expand Down Expand Up @@ -132,5 +130,30 @@
</logRemoteCommands>
</features>
</settings>
<userparameters>
<userparameter type="ArrayField">
<id type="UniqueIdField">
<Required>Y</Required>
</id>
<enabled type="BooleanField">
<default>1</default>
<Required>Y</Required>
</enabled>
<key type="TextField">
<mask>/^[^\t^,^;^\.^\[^\]^\{^\}]{1,255}$/u</mask>
<ValidationMessage>Should be a string between 1 and 255 characters.</ValidationMessage>
<Required>Y</Required>
</key>
<command type="TextField">
<mask>/^[^\t^,^;^\.^\[^\]^\{^\}]{1,4096}$/u</mask>
<ValidationMessage>Should be a string between 1 and 4096 characters.</ValidationMessage>
<Required>Y</Required>
</command>
<acceptParams type="BooleanField">
<default>0</default>
<Required>Y</Required>
</acceptParams>
</userparameter>
</userparameters>
</items>
</model>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ $( document ).ready(function() {
updateServiceControlUI('zabbixagent');
});

/***********************************************************************
* link grid actions
**********************************************************************/

$("#grid-userparameters").UIBootgrid(
{ search:'/api/zabbixagent/settings/searchUserparameters',
get:'/api/zabbixagent/settings/getUserparameter/',
set:'/api/zabbixagent/settings/setUserparameter/',
add:'/api/zabbixagent/settings/addUserparameter/',
del:'/api/zabbixagent/settings/delUserparameter/',
toggle:'/api/zabbixagent/settings/toggleUserparameter/',
options: {
rowCount:[10,25,50,100,500,1000]
}
}
);

/***********************************************************************
* Commands
**********************************************************************/
Expand All @@ -45,6 +62,7 @@ $( document ).ready(function() {
$(this).click(function(){
var frm_id = $(this).closest("form").attr("id");
var frm_title = $(this).closest("form").attr("data-title");

// save data for tab
saveFormToEndpoint(url="/api/zabbixagent/settings/set",formid=frm_id,callback_ok=function(){
// set progress animation when reloading
Expand All @@ -66,6 +84,33 @@ $( document ).ready(function() {
} else {
updateServiceControlUI('zabbixagent');
}
// when done, disable progress animation.
$("#"+frm_id+"_progress").removeClass("fa fa-spinner fa-pulse");
});
});
});
});

// Reconfigure - activate changes
$('[id*="reconfigureAct"]').each(function(){
$(this).click(function(){
// set progress animation
$('[id*="reconfigureAct_progress"]').each(function(){
$(this).addClass("fa fa-spinner fa-pulse");
});
// reconfigure service
ajaxCall(url="/api/zabbixagent/service/reconfigure", sendData={}, callback=function(data,status) {
if (status != "success" || data['status'] != 'ok') {
BootstrapDialog.show({
type: BootstrapDialog.TYPE_WARNING,
title: "{{ lang._('Error reconfiguring Zabbix Agent') }}",
message: data['status'],
draggable: true
});
}
// when done, disable progress animation
$('[id*="reconfigureAct_progress"]').each(function(){
$(this).removeClass("fa fa-spinner fa-pulse");
});
});
});
Expand All @@ -83,8 +128,57 @@ $( document ).ready(function() {

<ul class="nav nav-tabs" role="tablist" id="maintabs">
{{ partial("layout_partials/base_tabs_header",['formData':settingsForm]) }}

{# manually add tab menu #}
<li role="presentation" class="dropdown">
<a data-toggle="dropdown" href="#" class="dropdown-toggle pull-right visible-lg-inline-block visible-md-inline-block visible-xs-inline-block visible-sm-inline-block" role="button">
<b><span class="caret"></span></b>
</a>
<a data-toggle="tab" onclick="$('#userparameters-tab').click();" class="visible-lg-inline-block visible-md-inline-block visible-xs-inline-block visible-sm-inline-block" style="border-right:0px;"><b>{{ lang._('Advanced') }}</b></a>
<ul class="dropdown-menu" role="menu">
<li><a data-toggle="tab" id="userparameters-tab" href="#userparameters">{{ lang._('User Parameters') }}</a></li>
</ul>
</li>
</ul>

<div class="content-box tab-content">
{# add automatically generated tab content #}
{{ partial("layout_partials/base_tabs_content",['formData':settingsForm]) }}

{# manually add tab content #}
<div id="userparameters" class="tab-pane fade">
<!-- tab page "userparameters" -->
<table id="grid-userparameters" class="table table-condensed table-hover table-striped table-responsive" data-editDialog="DialogUserparameter">
<thead>
<tr>
<th data-column-id="enabled" data-width="6em" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
<th data-column-id="key" data-type="string">{{ lang._('User Parameter Key') }}</th>
<th data-column-id="command" data-type="string">{{ lang._('User Parameter Command') }}</th>
<th data-column-id="commands" data-width="7em" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
<button data-action="deleteSelected" type="button" class="btn btn-xs btn-default"><span class="fa fa-trash-o"></span></button>
</td>
</tr>
</tfoot>
</table>
<!-- apply button -->
<div class="col-md-12">
<hr/>
<button class="btn btn-primary" id="reconfigureAct-userparameters" type="button"><b>{{ lang._('Apply') }}</b><i id="reconfigureAct_progress" class=""></i></button>
<br/>
<br/>
</div>
</div>
</div>

{# include dialogs #}
{{ partial("layout_partials/base_dialog",['fields':formDialogUserparameter,'id':'DialogUserparameter','label':lang._('Edit User Parameter')]) }}
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,16 @@ Include=/usr/local/etc/zabbix_agentd.conf.d
# See 'zabbix_agentd' directory for examples.
#
# Disabled. A configuration file should be placed on directory: <%= @include %>
{% if helpers.exists('OPNsense.ZabbixAgent.userparameters') %}
{% for userparam in helpers.toList('OPNsense.ZabbixAgent.userparameters.userparameter') %}
{% if userparam.enabled == '1' %}
{% if userparam.acceptParams == '1' %}
{% set userparam_opts = '[*]' %}
{% endif %}
UserParameter={{userparam.key}}{{userparam_opts}},{{userparam.command}}
{% endif %}
{% endfor %}
{% endif %}

####### LOADABLE MODULES #######
### Option: LoadModulePath
Expand Down

0 comments on commit 6764f7e

Please sign in to comment.