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

net-mgmt/zabbix-agent: add Zabbix Agent to plugins #97

Merged
merged 2 commits into from
Mar 27, 2017

Conversation

fraenki
Copy link
Member

@fraenki fraenki commented Mar 23, 2017

From the authors of Zabbix:

Zabbix is the ultimate enterprise-level software designed for real-time monitoring of millions of metrics collected from tens of thousands of servers, virtual machines and network devices.
Zabbix is Open Source and comes at no cost.

This will add the Zabbix Agent to our growing list of plugins, effectively allowing OPNsense to be monitored with Zabbix.

This version of the plugin is ready for use, but not feature complete (from my point of view). Thus I've set the version to 0.1 for now.

The wishlist for version 1.0 (or later):

  • allow to create UserParameter entries (arbitrary shell commands, run as Zabbix user)
  • provide a set of pre-defined OPNsense checks (pf stats, IPsec status, configd commands, OPNsense API calls)
  • automatically generate firewall rules from ListenIP/ListenPort and Servers/ActiveServers
  • fix the log file in GUI (see security/acme-client: logfile is scrambled in the GUI #69)

@fraenki fraenki self-assigned this Mar 23, 2017
@fraenki fraenki requested a review from fichtner March 23, 2017 17:05
Copy link
Member

@fabianfrz fabianfrz left a comment

Choose a reason for hiding this comment

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

Added some comments to the code.

$result['section'] = 'OPNsense.zabbixagent';
$result['description'] = gettext('Enterprise-class open source distributed monitoring agent');
return array($result);
}
Copy link
Member

Choose a reason for hiding this comment

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

Seems to be not final.

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it's a warning to myself and others what should be considered before enabling sync :)

# Default:
# TLSPSKFile=

{% endif %}
Copy link
Member

Choose a reason for hiding this comment

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

In a generated configuration file, documentation comments are bloat.

Copy link
Member Author

@fraenki fraenki Mar 27, 2017

Choose a reason for hiding this comment

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

I think it is a good habit to keep comments in the sample configuration to give an idea about a certain value and it's usefulness. It's a very common thing to do.

{% if OPNsense.ZabbixAgent.settings.features.enableActiveChecks == '1' and OPNsense.ZabbixAgent.settings.features.activeCheckServers|default("") != "" %}
ServerActive={{OPNsense.ZabbixAgent.settings.features.activeCheckServers}}
{% else %}
# NOTE: Active checks are disabled
Copy link
Member

Choose a reason for hiding this comment

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

useless control path

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed.

$logfile = '/var/log/zabbix/zabbix_agentd.log';
$logclog = false;

require_once 'diag_logs_template.inc';
Copy link
Member

Choose a reason for hiding this comment

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

probably should be integrated into MVC, so the log can be downloaded via the API.

Copy link
Member

Choose a reason for hiding this comment

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

there is a PR open if anyone wants to touch that.....

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is outside the scope of this plugin.

<activeCheckServers type="CSVListField">
<Required>N</Required>
<multiple>Y</multiple>
<mask>/^([a-zA-Z0-9\.:\[\]\s\-]*?,)*([a-zA-Z0-9\.:\[\]\s\-]*)$/</mask>
Copy link
Member

Choose a reason for hiding this comment

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

whitespace (\s) in host:port combinations?

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed \s.

<val_2>2 - error information</val_2>
<val_3>3 - warnings [default]</val_3>
<val_4>4 - debugging</val_4>
<val_5>5 - extended debugging</val_5>
Copy link
Member

Choose a reason for hiding this comment

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

probably remove the numbers as the user receives the strings. It is probably better to use round brackets because it would fit better into the rest of the system.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, in Zabbix the number is actually the debug level. The text is just a vague description. I'm not against removing it, it's just that this is the most precise information...

Regarding the brackets, do you have some examples? I've not seen other GUI elements where the default value was highlighted in any way.

Copy link
Member

Choose a reason for hiding this comment

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

it is only one entry:
3 - warnings [default] -> 3 - warnings (default)
or even better:
warnings (default)

Copy link
Member

Choose a reason for hiding this comment

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

The most readable is:

"Warnings (3, default)"
"Debugging (4)"
"Extended debugging (5)"

Numbers don't have to be omitted, but we can't assume users know / want to know what numbers correspond to what meaning. It also makes translations clearer.

Copy link
Member Author

@fraenki fraenki Mar 27, 2017

Choose a reason for hiding this comment

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

@fabianfrz Yes, I know what entry you mean... I just wanted to see some examples why round brackets would be better suited. I know at least one example where round brackets would look really strange. And since I couldn't find any other highlighting for default values I've started using this variation for my other plugins already.

Copy link
Member Author

Choose a reason for hiding this comment

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

@fichtner Nice proposal, I'll change it accordingly.

public function indexAction()
{
// set page title
$this->view->title = "Zabbix Agent Settings";
Copy link
Member

Choose a reason for hiding this comment

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

gettext

Copy link
Member

Choose a reason for hiding this comment

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

yessir!

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed. And I will fix this for the "hello world" plugin too ;)

PLUGIN_VERSION= 0.1
PLUGIN_COMMENT= Enterprise-class open source distributed monitoring agent
PLUGIN_DEPENDS= zabbix32-agent
PLUGIN_MAINTAINER= opnsense@moov.de
Copy link
Member

Choose a reason for hiding this comment

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

maybe align the values

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed. Tabs are evil.

@fabianfrz
Copy link
Member

please add a package description (same directory as the makefile). This will be shown to the user in the future if he wants more information about the plugin.

Copy link
Member

@fichtner fichtner left a comment

Choose a reason for hiding this comment

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

good work, just being picky

PLUGIN_COMMENT= Enterprise-class open source distributed monitoring agent
PLUGIN_DEPENDS= zabbix32-agent
PLUGIN_MAINTAINER= opnsense@moov.de

Copy link
Member

Choose a reason for hiding this comment

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

PLUGIN_DEVEL=yes

Copy link
Member Author

Choose a reason for hiding this comment

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

Added.

PLUGIN_NAME= zabbix-agent
PLUGIN_VERSION= 0.1
PLUGIN_COMMENT= Enterprise-class open source distributed monitoring agent
PLUGIN_DEPENDS= zabbix32-agent
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

There's no point using such an outdated version anymore. I strongly suggest to use 3.2 (or at a minimum 3.0) by now.

Copy link
Member

Choose a reason for hiding this comment

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

I misread 32 as 23... ok, will update tools.git

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe also add a upgrade warning to the release notes, just in case someone is already using Zabbix Agent on OPNsense without a GUI.

Copy link
Member

Choose a reason for hiding this comment

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

the package name changes, no problem until they install the plugin, but I'll try to think of something.

*/

/**
XXX: needs investigation, hostname must be unique/replaced/excluded on secondary node(s)
Copy link
Member

Choose a reason for hiding this comment

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

yes, this is really bad for sync. why not use the system hostname instead to avoid the clash?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can't just use the hostname. It must match the hostname in the Zabbix Server, otherwise many checks will not work. That's why it must be configurable.

$response = $backend->configdRun("zabbixagent status");

if (strpos($response, "not running") > 0) {
if ($mdlAgent->settings->main->enabled->__toString() == 1) {
Copy link
Member

Choose a reason for hiding this comment

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

although just boilerplate, it's quirky: __toString() == "1"

}
} elseif (strpos($response, "is running") > 0) {
$status = "running";
} elseif ($mdlAgent->settings->main->enabled->__toString() == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

"0"

@@ -0,0 +1,11 @@
#!/bin/sh

AGENT_DIRS="/var/run/zabbix /var/log/zabbix /usr/local/etc/zabbix_agentd.d"
Copy link
Member

Choose a reason for hiding this comment

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

have you double checked with pkg-plist files? they can have other important dirs.

note this is also mostly for /var if MFS was enabled as /usr/local is persistent and likely created by the package install

https://github.com/opnsense/ports/tree/47aa039c8c8f361193e18a636760392971ef57ae/net-mgmt/zabbix24-server

Copy link
Member Author

@fraenki fraenki Mar 27, 2017

Choose a reason for hiding this comment

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

Well, in theory the package creates %%ETCDIR%%/zabbix_agentd.conf.d, but it doesn't work for me (it's not being created on package install). I've changed the code to use this (FreeBSD) default directory instead, but I let setup.sh create the directory.

@@ -0,0 +1,34 @@
[setup]
Copy link
Member

Choose a reason for hiding this comment

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

is this called separately? if not can zap

Copy link
Member Author

Choose a reason for hiding this comment

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

Zapped.

message:restarting zabbix_agentd

[status]
command:/usr/local/etc/rc.d/zabbix_agentd status || exit 0
Copy link
Member

Choose a reason for hiding this comment

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

doesn't this return the status if you let it? not as script_output, then check for error

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed. Was using this most likely because of an old bug (in HAProxy plugin).

{% else %}
zabbix_agentd_enable=NO
{% endif %}
zabbix_agentd_config=/usr/local/etc/zabbix_agentd.conf
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh nice! I wasn't aware of this. Added.

$logfile = '/var/log/zabbix/zabbix_agentd.log';
$logclog = false;

require_once 'diag_logs_template.inc';
Copy link
Member

Choose a reason for hiding this comment

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

there is a PR open if anyone wants to touch that.....

fraenki added a commit to fraenki/plugins that referenced this pull request Mar 27, 2017
@fraenki
Copy link
Member Author

fraenki commented Mar 27, 2017

@fabianfrz @fichtner Thanks for your feedback! I've incorporated all changes. Let me know if more should be changed/fixed.

@fabianfrz
Copy link
Member

looks OK to me.

@fraenki
Copy link
Member Author

fraenki commented Mar 27, 2017

zabbixagent

@fraenki fraenki merged commit 158f230 into opnsense:master Mar 27, 2017
@fichtner
Copy link
Member

@fraenki FYI, I had to do this opnsense/tools@54a0e5616337 due to the bump to 3.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants