summaryrefslogtreecommitdiffstats
path: root/plugins/nscautils.py.in
diff options
context:
space:
mode:
authorSahina Bose <sabose@redhat.com>2014-04-01 17:08:18 +0530
committerBala.FA <barumuga@redhat.com>2014-04-29 10:14:33 +0530
commited8efbc2adb78ab756081b1f57dd23328123a1d5 (patch)
treec42214c1778c1fea724a4479e95f2f9d506ff53d /plugins/nscautils.py.in
parent86a404d7ce805a25762cd66c310b1ad9e3a2a779 (diff)
plugins: Plugin to act on syslog message
This plugin integrates with syslog messages and sends the output to Nagios server using NSCA Refactored code to separate out common NSCA related code to nscautils Change-Id: I6a874da7f2296310060742acb6b1cd6562f5d0f0 Signed-off-by: Sahina Bose <sabose@redhat.com>
Diffstat (limited to 'plugins/nscautils.py.in')
-rw-r--r--plugins/nscautils.py.in53
1 files changed, 53 insertions, 0 deletions
diff --git a/plugins/nscautils.py.in b/plugins/nscautils.py.in
new file mode 100644
index 0000000..289d0d1
--- /dev/null
+++ b/plugins/nscautils.py.in
@@ -0,0 +1,53 @@
+# nscautils.py --utility methods to interact with Nagios NSCA
+# Copyright (C) 2014 Red Hat Inc
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+#
+
+import ConfigParser
+
+from glusternagios import utils
+
+__NAGIOSSERVER_CONF = "@nagiosconf@/nagios_server.conf"
+__NSCA_CONF_PATH = "@nagiosconf@/send_nsca.cfg"
+__NSCA_CMD_PATH = utils.CommandPath("nsca", "/usr/sbin/send_nsca")
+
+
+def getNagiosServerIP():
+ config = ConfigParser.ConfigParser()
+ config.read(__NAGIOSSERVER_CONF)
+ return config.get('NAGIOS-SERVER', 'nagios_server')
+
+
+def getNagiosClusterName():
+ config = ConfigParser.ConfigParser()
+ config.read(__NAGIOSSERVER_CONF)
+ return config.get('NAGIOS-DEFINTIONS', 'cluster_name')
+
+
+def send_to_nsca(hostName, serviceName, exitStatus, resultString):
+ cmddata = '%s\t%s\t%s\t%s' % (hostName,
+ serviceName,
+ exitStatus,
+ resultString)
+ nagiosIP = getNagiosServerIP()
+ command_send_nsca = [__NSCA_CMD_PATH, '-H', nagiosIP,
+ '-c', __NSCA_CONF_PATH]
+ ret, out, err = utils.execCmd(command_send_nsca, data=cmddata)
+ return ret
+
+
+def vol_service_name(volName, statusType=None):
+ return "Volume Status %s - %s" % (statusType, volName)