Skip to content

Commit

Permalink
feat: Introduce xymon-client plugin
Browse files Browse the repository at this point in the history
Closes #4259
  • Loading branch information
kumy committed Sep 28, 2024
1 parent db59671 commit 9d9929b
Show file tree
Hide file tree
Showing 16 changed files with 378 additions and 0 deletions.
15 changes: 15 additions & 0 deletions net-mgmt/xymon-client/+POST_INSTALL.post
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

# We need to add one "include" line in the default config file from xymon-client
# to load values from our own template

INCLUDE="include /usr/local/etc/xymon/xymonclient.cfg"
FILE=/usr/local/www/xymon/client/etc/xymonclient.cfg

grep -q "^${INCLUDE}$" "${FILE}" && exit 0

sed -i '' "/^LOGFETCHOPTS=/a \\
\\
# Added by OPNsense os-xymon-client plugin\\
${INCLUDE}\\
" "${FILE}"
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= github+opnsense-xymon-client@kumy.net

.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
67 changes: 67 additions & 0 deletions net-mgmt/xymon-client/src/etc/inc/plugins.inc.d/xymon.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?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 xymon_services()
{
global $config;

$services = [];

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

if (
isset($config['kumy']['xymon']['enabled']) &&
$config['kumy']['xymon']['enabled'] == 1
) {
$services[] = [
'description' => gettext('Xymon client'),
'configd' => [
'restart' => ['xymon restart'],
'start' => ['xymon start'],
'stop' => ['xymon stop'],
],
'name' => 'xymon',
'pidfile' => "/usr/local/www/xymon/client/logs/clientlaunch.$fqdn.pid"
];
}

return $services;
}

function xymon_xmlrpc_sync()
{
$result = [];

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

return $result;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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\Xymon\Api;

use OPNsense\Base\ApiMutableServiceControllerBase;
use OPNsense\Core\Backend;

class ServiceController extends ApiMutableServiceControllerBase
{
protected static $internalServiceClass = '\Kumy\Xymon\Settings';
protected static $internalServiceTemplate = 'Kumy\Xymon';
protected static $internalServiceEnabled = 'enabled';
protected static $internalServiceName = 'xymon';

public function reloadAction()
{
$status = 'failed';
if ($this->request->isPost()) {
$status = strtolower(trim((new Backend())->configdRun('template reload Kumy/Xymon')));
}
return ['status' => $status];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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\Xymon\Api;

use OPNsense\Base\ApiMutableModelControllerBase;

class SettingsController extends ApiMutableModelControllerBase
{
protected static $internalModelClass = '\Kumy\Xymon\Settings';
protected static $internalModelName = 'xymon';
}
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\Xymon;

class IndexController extends \OPNsense\Base\IndexController
{
public function indexAction()
{
$this->view->formSettings = $this->getForm('settings');
$this->view->pick('Kumy/Xymon/index');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<form>
<field>
<id>xymon.enabled</id>
<label>Enabled</label>
<type>checkbox</type>
</field>
<field>
<id>xymon.XYMSERVERS</id>
<label>Server addresses</label>
<type>text</type>
<help>Xymon server addresses.</help>
</field>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<menu>
<Services>
<Xymon cssClass="fa fa-heartbeat fa-fw" url="/ui/xymon"></Xymon>
</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\Xymon;

use OPNsense\Base\BaseModel;

class Settings extends BaseModel {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<model>
<mount>//kumy/xymon</mount>
<description>Xymon Settings</description>
<version>0.0.0</version>
<items>
<enabled type="BooleanField">
<default>1</default>
<Required>Y</Required>
</enabled>
<XYMSERVERS type="TextField">
<default/>
<Required>N</Required>
</XYMSERVERS>
</items>
</model>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<script type="text/javascript">
$(document).ready(function() {
function spinStart(selector) {
$(selector).addClass("fa fa-spinner fa-pulse");
}
function spinStop(selector) {
$(selector).removeClass("fa fa-spinner fa-pulse");
}

mapDataToFormUI({"frm_Settings": "/api/xymon/settings/get"}).done(function(data) {
updateServiceControlUI('xymon');
});

// Handle save button
$("body").on("click", ".save-button", function() {
spinStart("#button-save_progress");
saveFormToEndpoint("/api/xymon/settings/set", "frm_Settings", function() {
ajaxCall(url="/api/xymon/service/reload", sendData={}, callback=function(data, status) {
spinStop("#button-save_progress");
setTimeout(function() {
window.location.reload(true)
}, 300);
});
});
});

});
</script>

{%- macro action_button(button, text, class="btn-default") %}
<button class="btn btn-{{ class }} {{ button }}-button" type="button">
<b>{{ text }}</b>
<i id="button-{{ button }}_progress"></i>
</button>
{%- endmacro %}

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

<div class="content-box">
<div class="col-md-12">
<br/>
{{ action_button("save", lang._("Save"), "primary") }}
<br/><br/>
</div>
</div>
</section>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[start]
command: /usr/local/www/xymon/client/runclient.sh start
parameters:
type:script
message:xymon service start

[stop]
command: /usr/local/www/xymon/client/runclient.sh stop
parameters:
type:script
message:xymon service stop

[restart]
command: /usr/local/www/xymon/client/runclient.sh restart
parameters:
type:script
message:xymon service restart

[status]
command: /usr/local/www/xymon/client/runclient.sh status && echo "xymon client is running" || echo "xymon client is not running"
parameters:
type:script_output
message:xymon service status
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xymonclient.cfg:/usr/local/etc/xymon/xymonclient.cfg
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.XYMSERVERS') %}{{ kumy.xymon.XYMSERVERS }}{% endif %}"

0 comments on commit 9d9929b

Please sign in to comment.