From 1ceb9f9df28cdcbf2785229df2002c5112e71cca Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Sun, 20 Nov 2016 11:54:21 +0100 Subject: [PATCH] bsnmpd: check in actual plugin file --- src/etc/inc/plugins.inc.d/bsnmpd.inc | 226 +++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 src/etc/inc/plugins.inc.d/bsnmpd.inc diff --git a/src/etc/inc/plugins.inc.d/bsnmpd.inc b/src/etc/inc/plugins.inc.d/bsnmpd.inc new file mode 100644 index 000000000..3e8dc2f4e --- /dev/null +++ b/src/etc/inc/plugins.inc.d/bsnmpd.inc @@ -0,0 +1,226 @@ + + Copyright (C) 2010 Ermal Luci + Copyright (C) 2005-2006 Colin Smith + Copyright (C) 2003-2004 Manuel Kasper + 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. +*/ + +function bsnmpd_enabled() +{ + global $config; + + return isset($config['snmpd']['enable']); +} + +function bsnmpd_services() +{ + $services = array(); + + if (!bsnmpd_enabled()) { + return $services; + } + + $pconfig = array(); + $pconfig['name'] = 'bsnmpd'; + $pconfig['description'] = gettext('SNMP Service'); + $pconfig['php']['restart'] = array('bsnmpd_configure_do'); + $pconfig['php']['start'] = array('bsnmpd_configure_do'); + $pconfig['pidfile'] = '/var/run/snmpd.pid'; + $services[] = $pconfig; + + return $services; +} + +function bsnmpd_configure() +{ + return array('bsnmpd_configure_do'); +} + +function bsnmpd_configure_do($verbose = false) +{ + global $config, $g; + + killbypid('/var/run/snmpd.pid', 'TERM', true); + + if (!bsnmpd_enabled()) { + return; + } + + if ($verbose) { + echo 'Starting SNMP daemon...'; + flush(); + } + + /* generate snmpd.conf */ + $fd = fopen("/var/etc/snmpd.conf", "w"); + if (!$fd) { + log_error('Cannot open snmpd.conf in bsnmpd_configure_do()'); + return; + } + + $snmpdconf = <<