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

feat: Introduce xymon-client plugin #4260

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions net-mgmt/xymon-client/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Kumy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 8 additions & 0 deletions net-mgmt/xymon-client/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PLUGIN_NAME= xymon-client
PLUGIN_VERSION= 1.0.0
PLUGIN_REVISION= 1
PLUGIN_DEPENDS= xymon-client
PLUGIN_COMMENT= Client for the Xymon network monitor
PLUGIN_MAINTAINER= [email protected]

.include "../../Mk/plugins.mk"
13 changes: 13 additions & 0 deletions net-mgmt/xymon-client/pkg-descr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Client data collection package for Xymon (previously known as Hobbit).

This gathers statistics and data from a single system and reports it to
the Xymon monitor.

WWW: https://sourceforge.net/projects/xymon/

Plugin Changelog
================

1.0.0

* Initial release
69 changes: 69 additions & 0 deletions net-mgmt/xymon-client/src/etc/inc/plugins.inc.d/xymonclient.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/*
Copyright (c) 2024 Kumy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

function xymonclient_enabled()
{
return (string)(new Kumy\XymonClient\Settings())->enabled == '1';
}

function xymonclient_services()
{
global $config;

$services = [];

$fqdn = sprintf('%s.%s',
$config['system']['hostname'],
$config['system']['domain'],
);

if (xymonclient_enabled()) {
$services[] = [
'description' => gettext('Xymon client'),
'configd' => [
'restart' => ['xymonclient restart'],
'start' => ['xymonclient start'],
'stop' => ['xymonclient stop'],
],
'name' => 'xymonclient',
'pidfile' => "/var/run/xymon/xymon_client.pid"
];
}

return $services;
}

function xymonclient_xmlrpc_sync()
{
$result = [];

$result[] = [
'description' => gettext('Xymon client'),
'section' => 'kumy.xymon.client',
'id' => 'xymonclient',
'services' => ['xymonclient'],
];

return $result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/*
Copyright (c) 2024 Kumy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

namespace Kumy\XymonClient\Api;

use OPNsense\Base\ApiMutableServiceControllerBase;

class ServiceController extends ApiMutableServiceControllerBase
{
protected static $internalServiceClass = '\Kumy\XymonClient\Settings';
protected static $internalServiceTemplate = 'Kumy\XymonClient';
protected static $internalServiceEnabled = 'enabled';
protected static $internalServiceName = 'xymonclient';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
Copyright (c) 2024 Kumy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

namespace Kumy\XymonClient\Api;

use OPNsense\Base\ApiMutableModelControllerBase;
use OPNsense\Core\Backend;

class SettingsController extends ApiMutableModelControllerBase
{
protected static $internalModelClass = '\Kumy\XymonClient\Settings';
protected static $internalModelName = 'xymonclient';

public function reconfigureAction()
{
$status = 'failed';
if ($this->request->isPost()) {
$backend = new Backend();
$status = strtolower(trim($backend->configdRun('template reload Kumy/XymonClient')));
if ($status === 'ok') {
$config = $this->getModel();
if ((string)$config->enabled == "1" && !empty((string)$config->XYMSERVERS)) {
$status = $backend->configdRun('xymonclient restart');
} else {
$status = $backend->configdRun('xymonclient stop');
}
}
}
return ['status' => strtolower(trim($status))];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/*
Copyright (c) 2024 Kumy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

namespace Kumy\XymonClient;

class IndexController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
$this->view->formSettings = $this->getForm('settings');
$this->view->pick('Kumy/XymonClient/index');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<form>
<field>
<id>xymonclient.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
</field>
<field>
<id>xymonclient.XYMSERVERS</id>
<label>Server addresses</label>
<type>select_multiple</type>
<allownew>true</allownew>
<separator> </separator>
<style>tokenize</style>
<help>Xymon server addresses.</help>
</field>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<menu>
<Services>
<XymonClient VisibleName="Xymon Client" cssClass="fa fa-heartbeat fa-fw" url="/ui/xymonclient"></XymonClient>
</Services>
</menu>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/*
Copyright (c) 2024 Kumy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

namespace Kumy\XymonClient;

use OPNsense\Base\BaseModel;

class Settings extends BaseModel {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<model>
<mount>//kumy/xymon/client</mount>
<description>Xymon client settings</description>
<version>0.0.0</version>
<items>
<enabled type="BooleanField">
<default>0</default>
<Required>Y</Required>
</enabled>
<XYMSERVERS type="HostnameField">
<Required>N</Required>
<IpAllowed>Y</IpAllowed>
<HostWildcardAllowed>N</HostWildcardAllowed>
<FqdnWildcardAllowed>N</FqdnWildcardAllowed>
<ZoneRootAllowed>N</ZoneRootAllowed>
<AsList>Y</AsList>
<FieldSeparator> </FieldSeparator>
</XYMSERVERS>
</items>
</model>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<script type="text/javascript">
$(function() {
mapDataToFormUI({"frm_Settings": "/api/xymonclient/settings/get"}).done(function(data) {
if ('frm_Settings' in data) {
updateServiceControlUI('xymonclient');
formatTokenizersUI();
}
});

$("#reconfigureAct").SimpleActionButton({
onPreAction: function() {
const dfObj = new $.Deferred();
saveFormToEndpoint("/api/xymonclient/settings/set", "frm_Settings", function() {
dfObj.resolve();
});
return dfObj;
}
});
});
</script>

<section class="page-content-main">
<div class="content-box">
{{ partial("layout_partials/base_form", ["fields": formSettings, "id": "frm_Settings"]) }}
</div>
<br><br>

<div class="content-box">
<div class="col-md-12">
<br/>
<button class="btn btn-primary" id="reconfigureAct"
data-endpoint='/api/xymonclient/settings/reconfigure'
data-label="{{ lang._('Apply') }}"
data-service-widget="xymonclient"
data-error-title="{{ lang._('Error reconfiguring Xymon Client') }}"
type="button"
></button>
<br/><br/>
</div>
</div>
</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[start]
command: service xymon-client start
parameters:
type:script
message:xymon-client service start

[stop]
command: service xymon-client stop
parameters:
type:script
message:xymon-client service stop

[restart]
command: service xymon-client restart
parameters:
type:script
message:xymon-client service restart

[status]
# Note: The rc script is exiting with errcode 1
# if the service is not running
command: service xymon-client status; exit 0
parameters:
type:script_output
message:xymon-client service status
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
xymonclient.cfg:/usr/local/etc/xymon/xymonclient.cfg
xymon_client:/etc/rc.conf.d/xymon_client
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xymon_client_enable={% if not helpers.empty('kumy.xymon.client.enabled') and not helpers.empty('kumy.xymon.client.XYMSERVERS') %}YES{% else %}NO{% endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Automatically managed config do not edit manually

XYMSRV="0.0.0.0"
XYMSERVERS="{% if not helpers.empty('kumy.xymon.client.XYMSERVERS') %}{{ kumy.xymon.client.XYMSERVERS }}{% endif %}"