net-mgmt/telegraf: add global tags (#856)

This commit is contained in:
Michael
2018-09-19 09:23:31 +02:00
committed by Franco Fichtner
parent 8b4d773224
commit 3b40fe3aaf
7 changed files with 201 additions and 6 deletions
@@ -0,0 +1,64 @@
<?php
/**
* Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/
namespace OPNsense\Telegraf\Api;
use \OPNsense\Base\ApiMutableModelControllerBase;
class KeyController extends ApiMutableModelControllerBase
{
static protected $internalModelName = 'key';
static protected $internalModelClass = '\OPNsense\Telegraf\Key';
public function searchKeyAction()
{
return $this->searchBase('keys.key', array("enabled", "name", "value"));
}
public function getKeyAction($uuid = null)
{
$this->sessionClose();
return $this->getBase('key', 'keys.key', $uuid);
}
public function addKeyAction()
{
return $this->addBase('key', 'keys.key');
}
public function delKeyAction($uuid)
{
return $this->delBase('keys.key', $uuid);
}
public function setKeyAction($uuid)
{
return $this->setBase('key', 'keys.key', $uuid);
}
public function toggleKeyAction($uuid)
{
return $this->toggleBase('keys.key', $uuid);
}
}
@@ -33,6 +33,7 @@ class GeneralController extends \OPNsense\Base\IndexController
public function indexAction()
{
$this->view->generalForm = $this->getForm("general");
$this->view->formDialogEditTelegrafKey = $this->getForm("dialogEditTelegrafKey");
$this->view->pick('OPNsense/Telegraf/general');
}
}
@@ -0,0 +1,20 @@
<form>
<field>
<id>key.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
<help>This will enable or disable the key mapping.</help>
</field>
<field>
<id>key.name</id>
<label>Name</label>
<type>text</type>
<help>Set the name of this mapping.</help>
</field>
<field>
<id>key.value</id>
<label>Value</label>
<type>text</type>
<help>Set the value of the defined key.</help>
</field>
</form>
@@ -0,0 +1,31 @@
<?php
/*
Copyright (C) 2018 Michael Muenz <m.muenz@gmail.com>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
namespace OPNsense\Telegraf;
use OPNsense\Base\BaseModel;
class Key extends BaseModel
{
}
@@ -0,0 +1,25 @@
<model>
<mount>//OPNsense/telegraf/key</mount>
<description>Telegraf key configuration</description>
<version>1.0.0</version>
<items>
<keys>
<key type="ArrayField">
<enabled type="BooleanField">
<default>1</default>
<Required>Y</Required>
</enabled>
<name type="TextField">
<default></default>
<Required>N</Required>
<mask>/^([0-9a-zA-Z._\-]){1,128}$/u</mask>
</name>
<value type="TextField">
<default></default>
<Required>N</Required>
<mask>/^([0-9a-zA-Z._\-]){1,128}$/u</mask>
</value>
</key>
</keys>
</items>
</model>
@@ -29,6 +29,7 @@ POSSIBILITY OF SUCH DAMAGE.
<ul class="nav nav-tabs" data-tabs="tabs" id="maintabs">
<li class="active"><a data-toggle="tab" href="#general">{{ lang._('General') }}</a></li>
<li><a data-toggle="tab" href="#keys">{{ lang._('Tags') }}</a></li>
</ul>
<div class="tab-content content-box tab-content">
<div id="general" class="tab-pane fade in active">
@@ -40,8 +41,38 @@ POSSIBILITY OF SUCH DAMAGE.
</div>
</div>
</div>
<div id="keys" class="tab-pane fade in">
<table id="grid-keys" class="table table-responsive" data-editDialog="dialogEditTelegrafKey">
<thead>
<tr>
<th data-column-id="enabled" data-type="string" data-formatter="rowtoggle">{{ lang._('Enabled') }}</th>
<th data-column-id="name" data-type="string" data-visible="true">{{ lang._('Name') }}</th>
<th data-column-id="value" data-type="string" data-visible="true">{{ lang._('Value') }}</th>
<th data-column-id="uuid" data-type="string" data-identifier="true" data-visible="false">{{ lang._('ID') }}</th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">{{ lang._('Commands') }}</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td colspan="5"></td>
<td>
<button data-action="add" type="button" class="btn btn-xs btn-default"><span class="fa fa-plus"></span></button>
</td>
</tr>
</tfoot>
</table>
<div class="col-md-12">
<hr />
<button class="btn btn-primary" id="saveAct_key" type="button"><b>{{ lang._('Save') }}</b> <i id="saveAct_key_progress"></i></button>
<br /><br />
</div>
</div>
</div>
{{ partial("layout_partials/base_dialog",['fields':formDialogEditTelegrafKey,'id':'dialogEditTelegrafKey','label':lang._('Edit Mapping')])}}
<script>
$( document ).ready(function() {
var data_get_map = {'frm_general_settings':"/api/telegraf/general/get"};
@@ -50,21 +81,36 @@ POSSIBILITY OF SUCH DAMAGE.
$('.selectpicker').selectpicker('refresh');
});
ajaxCall(url="/api/telegraf/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
updateServiceControlUI('telegraf');
$("#grid-keys").UIBootgrid(
{ 'search':'/api/telegraf/key/searchKey',
'get':'/api/telegraf/key/getKey/',
'set':'/api/telegraf/key/setKey/',
'add':'/api/telegraf/key/addKey/',
'del':'/api/telegraf/key/delKey/',
'toggle':'/api/telegraf/key/toggleKey/'
}
);
// link save button to API set action
$("#saveAct").click(function(){
saveFormToEndpoint(url="/api/telegraf/general/set", formid='frm_general_settings',callback_ok=function(){
$("#saveAct_progress").addClass("fa fa-spinner fa-pulse");
ajaxCall(url="/api/telegraf/service/reconfigure", sendData={}, callback=function(data,status) {
ajaxCall(url="/api/telegraf/service/status", sendData={}, callback=function(data,status) {
updateServiceStatusUI(data['status']);
});
updateServiceControlUI('telegraf');
$("#saveAct_progress").removeClass("fa fa-spinner fa-pulse");
});
});
});
$("#saveAct_key").click(function(){
saveFormToEndpoint(url="/api/telegraf/key/set", formid='frm_general_settings',callback_ok=function(){
$("#saveAct_key_progress").addClass("fa fa-spinner fa-pulse");
ajaxCall(url="/api/telegraf/service/reconfigure", sendData={}, callback=function(data,status) {
updateServiceControlUI('telegraf');
$("#saveAct_key_progress").removeClass("fa fa-spinner fa-pulse");
});
});
});
});
</script>
@@ -2,6 +2,14 @@
[global_tags]
{% if helpers.exists('OPNsense.telegraf.key.keys.key') %}
{% for key_list in helpers.toList('OPNsense.telegraf.key.keys.key') %}
{% if key_list.enabled == '1' %}
{{ key_list.name }} = "{{ key_list.value }}"
{% endif %}
{% endfor %}
{% endif %}
[agent]
{% if helpers.exists('OPNsense.telegraf.general.interval') and OPNsense.telegraf.general.interval != '' %}
interval = "{{ OPNsense.telegraf.general.interval }}s"