Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions net-mgmt/zabbix-agent/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PLUGIN_NAME= zabbix-agent
PLUGIN_VERSION= 0.1
PLUGIN_COMMENT= Enterprise-class open source distributed monitoring agent
PLUGIN_DEPENDS= zabbix32-agent
PLUGIN_DEVEL= yes
PLUGIN_MAINTAINER= opnsense@moov.de

.include "../../Mk/plugins.mk"
1 change: 1 addition & 0 deletions net-mgmt/zabbix-agent/pkg-descr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Manage the Zabbix Agent to allow OPNsense to be monitored by a Zabbix Server.
86 changes: 86 additions & 0 deletions net-mgmt/zabbix-agent/src/etc/inc/plugins.inc.d/zabbixagent.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?php

/**
* Copyright (C) 2017 Frank Wall
* 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.
*/

function zabbixagent_enabled()
{
global $config;

return isset($config['OPNsense']['ZabbixAgent']['settings']['main']['enabled']) &&
$config['OPNsense']['ZabbixAgent']['settings']['main']['enabled'] == 1;
}

function zabbixagent_firewall($fw)
{
if (!zabbixagent_enabled()) {
return;
}

$fw->registerAnchor('zabbix-agent/*', 'nat');
$fw->registerAnchor('zabbix-agent/*', 'rdr');
$fw->registerAnchor('zabbix-agent/*', 'fw');
}

/**
* register legacy service
* @return array
*/
function zabbixagent_services()
{
$services = array();

if (!zabbixagent_enabled()) {
return $services;
}

$services[] = array(
'description' => gettext('Enterprise-class open source distributed monitoring agent'),
'pidfile' => '/var/run/zabbix/zabbix_agentd.pid',
'configd' => array(
'restart' => array('zabbix_agentd restart'),
'start' => array('zabbix_agentd start'),
'stop' => array('zabbix_agentd stop'),
),
'name' => 'zabbix_agentd',
);

return $services;
}

/**
* sync configuration via xmlrpc
* @return array
*/

function zabbixagent_xmlrpc_sync()
{
$result = array();
$result['id'] = 'zabbixagent';
$result['section'] = 'OPNsense.zabbixagent.settings';
$result['description'] = gettext('Enterprise-class open source distributed monitoring agent');
return array($result);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php
/**
* Copyright (C) 2017 Frank Wall
* Copyright (C) 2015 Deciso B.V.
*
* 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\ZabbixAgent\Api;

use \OPNsense\Base\ApiControllerBase;
use \OPNsense\Core\Backend;
use \OPNsense\ZabbixAgent\ZabbixAgent;

/**
* Class ServiceController
* @package OPNsense\ZabbixAgent
*/
class ServiceController extends ApiControllerBase
{
/**
* start zabbix agent service (in background)
* @return array
*/
public function startAction()
{
if ($this->request->isPost()) {
$backend = new Backend();
$response = $backend->configdRun("zabbixagent start", true);
return array("response" => $response);
} else {
return array("response" => array());
}
}

/**
* stop zabbix agent service
* @return array
*/
public function stopAction()
{
if ($this->request->isPost()) {
$backend = new Backend();
$response = $backend->configdRun("zabbixagent stop");
return array("response" => $response);
} else {
return array("response" => array());
}
}

/**
* restart zabbix agent service
* @return array
*/
public function restartAction()
{
if ($this->request->isPost()) {
$backend = new Backend();
$response = $backend->configdRun("zabbixagent restart");
return array("response" => $response);
} else {
return array("response" => array());
}
}

/**
* retrieve status of zabbix agent service
* @return array
* @throws \Exception
*/
public function statusAction()
{
$backend = new Backend();
$mdlAgent = new ZabbixAgent();
$response = $backend->configdRun("zabbixagent status");

if (strpos($response, "not running") > 0) {
if ($mdlAgent->settings->main->enabled->__toString() == "1") {
$status = "stopped";
} else {
$status = "disabled";
}
} elseif (strpos($response, "is running") > 0) {
$status = "running";
} elseif ($mdlAgent->settings->main->enabled->__toString() == "0") {
$status = "disabled";
} else {
$status = "unkown";
}

return array("status" => $status);
}

/**
* reconfigure zabbix agent, generate config and reload
*/
public function reconfigureAction()
{
if ($this->request->isPost()) {
$force_restart = false;
// close session for long running action
$this->sessionClose();

$mdlAgent = new ZabbixAgent();
$backend = new Backend();

$runStatus = $this->statusAction();

// stop zabbix agent when disabled
if ($runStatus['status'] == "running" &&
($mdlAgent->settings->main->enabled->__toString() == "0" || $force_restart)) {
$this->stopAction();
}

// generate template
$backend->configdRun('template reload OPNsense/ZabbixAgent');

// (res)start daemon
if ($mdlAgent->settings->main->enabled->__toString() == "1") {
if ($runStatus['status'] == "running" && !$force_restart) {
$backend->configdRun("zabbixagent reconfigure");
} else {
$this->startAction();
}
}

return array("status" => "ok");
} else {
return array("status" => "failed");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Copyright (C) 2017 Frank Wall
* Copyright (C) 2015 Deciso B.V.
*
* 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\ZabbixAgent\Api;

use \OPNsense\Base\ApiMutableModelControllerBase;
use \OPNsense\Base\UIModelGrid;
use \OPNsense\Core\Config;
use \OPNsense\ZabbixAgent\ZabbixAgent;

/**
* Class SettingsController
* @package OPNsense\ZabbixAgent
*/
class SettingsController extends ApiMutableModelControllerBase
{
static protected $internalModelName = 'zabbixagent';
static protected $internalModelClass = '\OPNsense\ZabbixAgent\ZabbixAgent';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Copyright (C) 2017 Frank Wall
* Copyright (C) 2015 Deciso B.V.
*
* 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\ZabbixAgent;

/**
* Class IndexController
* @package OPNsense\ZabbixAgent
*/
class IndexController extends \OPNsense\Base\IndexController
{
/**
* zabbix agent index page
* @throws \Exception
*/
public function indexAction()
{
// set page title
$this->view->title = gettext('Zabbix Agent Settings');
// include form definitions
$this->view->settingsForm = $this->getForm("settings");
// pick the template to serve
$this->view->pick('OPNsense/ZabbixAgent/index');
}
}
Loading