Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when possible, I would prevent saving settings in the www directory, the post install script can be avoided by shipping the xymonclient.cfg for this plugin and using the template directory to flush it to disk (probably in stead of /usr/local/etc/xymon/xymonclient.cfg further below)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AdSchellevis like https://github.com/opnsense/plugins/pull/4260/files#r1835329433

I don't think this would be possible. The file /usr/local/www/xymon/client/etc/xymonclient.cfg is statically coded from file /usr/local/www/xymon/client/etc/clientlaunch.cfg

# cat /usr/local/www/xymon/client/etc/clientlaunch.cfg
#
# The clientlaunch.cfg file is loaded by "xymonlaunch".
# It controls which of the Xymon client-side modules to run, 
# (both the main client "xymonclient.sh" and any client-side
# extensions); how often, and with which parameters, options 
# and environment variables.
#
# Note: On the Xymon *server* itself, this file is normally 
#       NOT used. Instead, both the client- and server-tasks
#       are controlled by the tasks.cfg file.
#

# msgcache is used for passive clients, that cannot connect
# directly to the Xymon server. This is not the default
# setup, so this task is normally disabled.
[msgcache]
	DISABLED
	ENVFILE $XYMONCLIENTHOME/etc/xymonclient.cfg
	CMD $XYMONCLIENTHOME/bin/msgcache --no-daemon --pidfile=$XYMONCLIENTLOGS/msgcache.pid
	LOGFILE $XYMONCLIENTLOGS/msgcache.log

# The main client task
[client]
	ENVFILE $XYMONCLIENTHOME/etc/xymonclient.cfg
	CMD $XYMONCLIENTHOME/bin/xymonclient.sh 
	LOGFILE $XYMONCLIENTLOGS/xymonclient.log
	INTERVAL 5m

Which is called by the /usr/local/etc/rc.d/xymon-client from the non-overridable variable command_args="--config=/usr/local/www/xymon/client/etc/clientlaunch.cfg --log=/usr/local/www/xymon/client/logs/clientlaunch.log --pidfil e=${pidfile}"

Were you suggesting to completely overwrite the /usr/local/etc/rc.d/xymon-client file from the package to pass our own arguments?

@kumy kumy Nov 9, 2024

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some tests to override the /usr/local/etc/rc.d/xymon-client and setting pidfile="/var/run/xymonclient.pid" (as suggested here). This is preventing the service to start as /var/run/ is owned by root:wheel and perms are 0755 and the service is started as user xymon which don't have permission there.

EDIT: I circumvented this by patching the "forked" rc file and added the pid file creation and give it proper permission.

Next issue is giving execution bit to the /usr/local/etc/rc.d/xymon-client now managed by the template system :(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next issue is giving execution bit to the /usr/local/etc/rc.d/xymon-client now managed by the template system :(

Looks like I can't set it to executable

https://github.com/opnsense/core/blob/84437b3812d959a7aca7f1af8d6c528d8683607d/src/opnsense/service/modules/template.py#L287-L289

So I don't know how I can accomplish what you requested with this comment, neither how to change the pidfile path

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File removed here in favor of ports update see PR opnsense/ports#206


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
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' => "/usr/local/www/xymon/client/logs/clientlaunch.$fqdn.pid"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
'pidfile' => "/usr/local/www/xymon/client/logs/clientlaunch.$fqdn.pid"
'pidfile' => "/var/run/xymonclient.pid"

Two reasons, when making the pid dynamic, restart behavior might get flaky and the usual directory is /var/run and not exposed via the webserver.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AdSchellevis
This is not my choice. It's defined in file /usr/local/etc/rc.d/xymon-client from the package itself.

Excerpt:

#!/bin/sh

# PROVIDE: xymon_client
# REQUIRE: DAEMON
# KEYWORD: shutdown

. /etc/rc.subr

name=xymon_client
rcvar=xymon_client_enable

load_rc_config "$name"
: ${xymon_client_enable:=NO}
: ${xymon_client_user:=xymon}

pidfile="/usr/local/www/xymon/client/logs/clientlaunch.`hostname`.pid"
command=/usr/local/www/xymon/client/bin/xymonlaunch
command_args="--config=/usr/local/www/xymon/client/etc/clientlaunch.cfg --log=/usr/local/www/xymon/client/logs/clientlaunch.log --pidfile=${pidfile}"
start_precmd=xymon_precmd

[…]

The variable pidfile is not overridable as it uses = and not something like : ${pidfile:=...}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can change the port rc.d script to better handle an external pid. Eventually we need to do something about the FreeBSD port itself though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done see latest commit and PR opnsense/ports#206

];
}

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 || true
Comment thread
kumy marked this conversation as resolved.
Outdated
parameters:
type:script_output
message:xymon-client service status
Loading