aboutsummaryrefslogtreecommitdiffstats
path: root/config/nrpe2
diff options
context:
space:
mode:
Diffstat (limited to 'config/nrpe2')
-rw-r--r--config/nrpe2/nrpe2.inc98
-rw-r--r--config/nrpe2/nrpe2.priv.inc37
-rw-r--r--config/nrpe2/nrpe2.xml50
3 files changed, 125 insertions, 60 deletions
diff --git a/config/nrpe2/nrpe2.inc b/config/nrpe2/nrpe2.inc
index 08aeb5c4..5a23a585 100644
--- a/config/nrpe2/nrpe2.inc
+++ b/config/nrpe2/nrpe2.inc
@@ -28,7 +28,9 @@
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
-require_once('filter.inc');
+require_once("filter.inc");
+require_once("pkg-utils.inc");
+require_once("util.inc");
global $pfs_version;
$pfs_version = substr(trim(file_get_contents("/etc/version")), 0, 3);
@@ -50,20 +52,9 @@ define('NRPE_RCFILE', '/usr/local/etc/rc.d/nrpe2.sh');
function nrpe2_custom_php_install_command() {
- global $g, $config;
- $NRPE_BASE = NRPE_BASE;
- $NRPE_CONFIG_DIR = NRPE_CONFIG_DIR;
-
- $ip = $config['interfaces']['lan']['ipaddr'];
-
- if (!is_array($config['installedpackages']['nrpe2'])) {
- $config['installedpackages']['nrpe2']['config'][0]['enabled'] = "on";
- $config['installedpackages']['nrpe2']['config'][0]['server_address'] = $ip;
- $config['installedpackages']['nrpe2']['config'][0]['server_port'] = 5666;
- $config['installedpackages']['nrpe2']['config'][0]['allowed_hosts'] = "127.0.0.1";
- $config['installedpackages']['nrpe2']['config'][0]['dont_blame_nrpe'] = "on";
- }
+ global $config;
+ /* Create default commands configuration */
if (!is_array($config['installedpackages']['nrpe2']['config'][0]['row'])) {
$config['installedpackages']['nrpe2']['config'][0]['row'] = array(
0 => array(
@@ -107,8 +98,19 @@ function nrpe2_custom_php_install_command() {
)
);
}
+
+ /* Remove the rc script installed with the package */
unlink_if_exists(NRPE_CONFIG_DIR . '/rc.d/nrpe2');
- $nrpe2_binary = NRPE_BINARY;
+
+}
+
+function nrpe2_custom_php_deinstall_command() {
+ unlink_if_exists(NRPE_RCFILE);
+}
+
+function nrpe2_write_rc_file() {
+ $NRPE_CONFIG_DIR = NRPE_CONFIG_DIR;
+ $NRPE2_BINARY = NRPE_BINARY;
$fd = fopen(NRPE_RCFILE, 'w');
$rc_file = <<<EOD
#!/bin/sh
@@ -135,7 +137,7 @@ nrpe2_enable=\${nrpe2_enable-"YES"}
name="nrpe2"
rcvar="\${name}_enable"
-command="{$nrpe2_binary}"
+command="{$NRPE2_BINARY}"
command_args="-d"
extra_commands="reload"
@@ -160,31 +162,34 @@ EOD;
}
+function nrpe2_resync_package() {
+ conf_mount_rw();
+ nrpe2_custom_php_write_config();
+ nrpe2_custom_php_service();
+ conf_mount_ro();
+}
+
function nrpe2_custom_php_write_config() {
- global $g, $config;
+ global $config;
$nagios_check_path = NRPE_BASE . "/libexec/nagios";
- conf_mount_rw();
$cmds = array();
foreach ($config['installedpackages']['nrpe2']['config'][0]['row'] as $cmd) {
$sudo_bin = "/usr/local/bin/sudo";
$sudo = (isset($cmd['sudo']) && is_executable($sudo_bin)) ? "{$sudo_bin} " : "";
$wcmd = !empty($cmd['warning']) ? "-w {$cmd['warning']}" : "";
$ccmd = !empty($cmd['critical']) ? "-c {$cmd['critical']}" : "";
- if (is_executable("{$nagios_check_path}/{$cmd['command']}"))
+ if (is_executable("{$nagios_check_path}/{$cmd['command']}")) {
$cmds[] = "command[{$cmd['name']}]={$sudo}{$nagios_check_path}/{$cmd['command']} {$wcmd} {$ccmd} {$cmd['extra']}\n";
+ }
}
$commands = implode($cmds);
- $server_port = $config['installedpackages']['nrpe2']['config'][0]['server_port'];
- $allowed_hosts = $config['installedpackages']['nrpe2']['config'][0]['allowed_hosts'];
- $dont_blame_nrpe = $config['installedpackages']['nrpe2']['config'][0]['dont_blame_nrpe'];
- if ($config['installedpackages']['nrpe2']['config'][0]['dont_blame_nrpe'] == "on") {
- $dont_blame_nrpe = 1;
- } else {
- $dont_blame_nrpe = 0;
- }
+ $server_port = $config['installedpackages']['nrpe2']['config'][0]['server_port'] ?: '5666';
+ $allowed_hosts = $config['installedpackages']['nrpe2']['config'][0]['allowed_hosts'] ?: '127.0.0.1';
+ $dont_blame_nrpe = $config['installedpackages']['nrpe2']['config'][0]['dont_blame_nrpe'] == "on" ? '1' : '0';
+ /* Create configuration file */
$fd = fopen(NRPE_CONFIG_DIR . '/nrpe.cfg', 'w');
$nrpe_cfg = <<<EOD
log_facility=daemon
@@ -199,22 +204,29 @@ command_timeout=60
connection_timeout=300
{$commands}
EOD;
- if (defined($config['installedpackages']['nrpe2']['config'][0]['server_address'])) {
- $server_address = $config['installedpackages']['nrpe2']['config'][0]['server_address'];
- $nrpe_cfg .= "server_address={$server_address}";
+ if ($config['installedpackages']['nrpe2']['config'][0]['server_address'] != "") {
+ $nrpe_cfg .= "server_address={$config['installedpackages']['nrpe2']['config'][0]['server_address']}";
}
fwrite($fd, $nrpe_cfg);
fclose($fd);
- conf_mount_ro();
+
}
function nrpe2_custom_php_service() {
global $config;
if ($config['installedpackages']['nrpe2']['config'][0]['enabled'] == "on") {
- restart_service("nrpe2");
+ nrpe2_write_rc_file();
+ if (is_service_running("nrpe2")) {
+ restart_service("nrpe2");
+ } else {
+ start_service("nrpe2");
+ }
} else {
- stop_service("nrpe2");
+ if (is_service_running("nrpe2")) {
+ stop_service("nrpe2");
+ }
+ unlink_if_exists(NRPE_RCFILE);
}
}
@@ -222,8 +234,26 @@ function nrpe2_get_commands() {
$nagios_check_path = NRPE_BASE . "/libexec/nagios";
$commands = glob("{$nagios_check_path}/check_*");
$cmdarr = array();
- foreach ($commands as $cmd)
+ foreach ($commands as $cmd) {
$cmdarr[]["command"] = basename($cmd);
+ }
return $cmdarr;
}
+
+function nrpe2_custom_php_validation_command($post, &$input_errors) {
+ if (!is_port($post['server_port'])) {
+ $input_errors[] = gettext("'Port Number' must be a valid port.");
+ }
+ if ($post['server_address'] != "") {
+ if (!is_ipaddr($post['server_address'])) {
+ $input_errors[] = gettext("'Bind IP Address' must be a valid IP address.");
+ }
+ }
+ foreach (explode(",", $post['allowed_hosts']) as $host) {
+ if (!empty($host) && !is_ipaddr($host)) {
+ $input_errors[] = gettext("'Nagios Server(s)' entry '{$host}' is not a valid IP address.");
+ }
+ }
+}
+
?>
diff --git a/config/nrpe2/nrpe2.priv.inc b/config/nrpe2/nrpe2.priv.inc
new file mode 100644
index 00000000..3014806a
--- /dev/null
+++ b/config/nrpe2/nrpe2.priv.inc
@@ -0,0 +1,37 @@
+<?php
+/*
+ nrpe2.priv.inc
+ part of pfSense (http://www.pfSense.org/)
+ Copyright (C) 2015 ESF, LLC
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+*/
+global $priv_list;
+
+$priv_list['page-services-nrpe2'] = array();
+$priv_list['page-services-nrpe2']['name'] = "WebCfg - Services: nrpe2 package";
+$priv_list['page-services-nrpe2']['descr'] = "Allow access to nrpe2 package GUI";
+$priv_list['page-services-nrpe2']['match'] = array();
+$priv_list['page-services-nrpe2']['match'][] = "pkg_edit.php?xml=nrpe2.xml*";
+
+?>
diff --git a/config/nrpe2/nrpe2.xml b/config/nrpe2/nrpe2.xml
index f70835c3..dcd6a5a9 100644
--- a/config/nrpe2/nrpe2.xml
+++ b/config/nrpe2/nrpe2.xml
@@ -42,10 +42,9 @@
/* ====================================================================================== */
]]>
</copyright>
- <description>Nagios NRPEv2</description>
<name>nrpe2</name>
- <version>2.2.1</version>
- <title>NRPEv2</title>
+ <version>2.2.2</version>
+ <title>Services: NRPEv2</title>
<aftersaveredirect>/pkg_edit.php?xml=nrpe2.xml&amp;id=0</aftersaveredirect>
<include_file>/usr/local/pkg/nrpe2.inc</include_file>
<menu>
@@ -58,35 +57,39 @@
<name>nrpe2</name>
<rcfile>nrpe2.sh</rcfile>
<executable>nrpe2</executable>
- <description>Nagios NRPE Daemon</description>
+ <description>Nagios NRPEv2 Daemon</description>
</service>
<configpath>installedpackages->package->nrpe2</configpath>
<additional_files_needed>
<prefix>/usr/local/pkg/</prefix>
<item>https://packages.pfsense.org/packages/config/nrpe2/nrpe2.inc</item>
</additional_files_needed>
+ <additional_files_needed>
+ <prefix>/etc/inc/priv/</prefix>
+ <item>https://packages.pfsense.org/packages/config/nrpe2/nrpe2.priv.inc</item>
+ </additional_files_needed>
<fields>
<field>
<type>listtopic</type>
- <name>NRPE Options</name>
- <fieldname>temp</fieldname>
+ <name>Service Options</name>
</field>
<field>
- <fielddescr>Enabled</fielddescr>
+ <fielddescr>Enable NRPE</fielddescr>
<fieldname>enabled</fieldname>
<description>Check this to enable NRPE daemon.</description>
<type>checkbox</type>
+ <default_value>on</default_value>
</field>
<field>
<type>listtopic</type>
<name>Configuration Options</name>
- <fieldname>temp</fieldname>
</field>
<field>
<fielddescr>Port Number</fielddescr>
<fieldname>server_port</fieldname>
<description>Port number we should wait for connections on. (Default: 5666)</description>
<type>input</type>
+ <default_value>5666</default_value>
<required/>
</field>
<field>
@@ -107,12 +110,12 @@
<fieldname>dont_blame_nrpe</fieldname>
<description>Check this to enable accept NRPE arguments. (Default: 0)</description>
<type>checkbox</type>
+ <default_value>on</default_value>
</field>
<field>
<type>listtopic</type>
<name>Commands</name>
- <fieldname>temp</fieldname>
</field>
<field>
<fielddescr>Command Definitions that the Nagios server can call via the NRPE daemon.</fielddescr>
@@ -158,34 +161,29 @@
<rowhelperfield>
<fielddescr>Extra Options (Example: -s Z \$ARG1\$ \$ARG2\$)</fielddescr>
<fieldname>extra</fieldname>
- <description><![CDATA[<strong>Warning! Use at your own risk, incorrect settings here may prevent NRPE from starting!</strong>]]></description>
+ <description>Warning! Use at your own risk, incorrect settings here may prevent NRPE from starting!</description>
<type>input</type>
<size>25</size>
</rowhelperfield>
</rowhelper>
</field>
</fields>
- <custom_delete_php_command>
- nrpe2_custom_php_write_config();
- nrpe2_custom_php_service();
- </custom_delete_php_command>
- <custom_add_php_command>
- nrpe2_custom_php_write_config();
- nrpe2_custom_php_service();
- </custom_add_php_command>
<custom_php_install_command>
nrpe2_custom_php_install_command();
- nrpe2_custom_php_write_config();
- nrpe2_custom_php_service();
</custom_php_install_command>
<custom_php_deinstall_command>
- nrpe2_custom_php_write_config();
+ nrpe2_custom_php_deinstall_command();
</custom_php_deinstall_command>
+ <custom_add_php_command>
+ nrpe2_resync_package();
+ </custom_add_php_command>
+ <custom_delete_php_command>
+ nrpe2_resync_package();
+ </custom_delete_php_command>
<custom_php_resync_config_command>
- nrpe2_custom_php_write_config();
- nrpe2_custom_php_service();
+ nrpe2_resync_package();
</custom_php_resync_config_command>
- <custom_php_command_before_form>
- unset($_POST['temp']);
- </custom_php_command_before_form>
+ <custom_php_validation_command>
+ nrpe2_custom_php_validation_command($_POST, $input_errors);
+ </custom_php_validation_command>
</packagegui>