-
Notifications
You must be signed in to change notification settings - Fork 849
feat: Introduce xymon-client plugin #4260
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
83c4dbf
b2ba355
2685bff
f2bf6f2
639ff46
2d9c392
37d76b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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}" | ||
| 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. |
| 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" |
| 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 |
| 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" | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Two reasons, when making the pid dynamic, restart behavior might get flaky and the usual directory is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AdSchellevis Excerpt: The variable
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
kumy marked this conversation as resolved.
Outdated
|
||
| parameters: | ||
| type:script_output | ||
| message:xymon-client service status | ||
There was a problem hiding this comment.
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
wwwdirectory, the post install script can be avoided by shipping thexymonclient.cfgfor this plugin and using the template directory to flush it to disk (probably in stead of/usr/local/etc/xymon/xymonclient.cfgfurther below)There was a problem hiding this comment.
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.cfgis statically coded from file/usr/local/www/xymon/client/etc/clientlaunch.cfgWhich is called by the
/usr/local/etc/rc.d/xymon-clientfrom the non-overridable variablecommand_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-clientfile from the package to pass our own arguments?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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-clientand settingpidfile="/var/run/xymonclient.pid"(as suggested here). This is preventing the service to start as/var/run/is owned byroot:wheeland perms are0755and the service is started as userxymonwhich 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-clientnow managed by the template system :(There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
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