From 6b1eef55ec692db337233c8f676b8725eae10652 Mon Sep 17 00:00:00 2001 From: Mahadev Konar Date: Wed, 7 Jan 2015 15:55:52 -0800 Subject: [PATCH] AMBARI-9012. Add Nagios-SNMP contrib to Ambari. (Cabir Zounaidou via mahadev) --- contrib/nagios-snmp/README.md | 99 +++++++++++++++++++ .../src/nagios/objects/snmp-commands.cfg | 33 +++++++ .../src/nagios/objects/snmp-contacts.cfg | 31 ++++++ .../nagios-snmp/src/scripts/send-host-trap | 29 ++++++ .../nagios-snmp/src/scripts/send-service-trap | 30 ++++++ 5 files changed, 222 insertions(+) create mode 100644 contrib/nagios-snmp/README.md create mode 100644 contrib/nagios-snmp/src/nagios/objects/snmp-commands.cfg create mode 100644 contrib/nagios-snmp/src/nagios/objects/snmp-contacts.cfg create mode 100644 contrib/nagios-snmp/src/scripts/send-host-trap create mode 100644 contrib/nagios-snmp/src/scripts/send-service-trap diff --git a/contrib/nagios-snmp/README.md b/contrib/nagios-snmp/README.md new file mode 100644 index 00000000000..dd76f462f69 --- /dev/null +++ b/contrib/nagios-snmp/README.md @@ -0,0 +1,99 @@ + + +Ambari Server integration with SNMP traps +========================================= +Ambari uses nagios to manage alerts in the cluster. When a node goes down or a service state changes in the cluster, nagios +will handle those events and is monitored using Ambari-web. This document describes how to integrate alerts with remote +SNMP management station by sending SNMP traps. By enabling SNMP traps, Ambari & Hadoop cluster alerts can be monitored +using remote management station (like OpenNMS, HP OpenView, etc.,). + + This will work with Ambari Server 1.7.0 and below. In Ambari 2.0.0, this feature will be + replaced by alert framework. + +Prerequisites: +-------------- +1. Nagios server should be running in one of the hadoop cluster node. (Need not to be same node as Ambari server). +2. SNMP should be installed in the node where nagios server is running. Run the following command to install net-snmp +and net-snmp-utils. +> yum install net-snmp net-snmp-utils net-snmp-devel +3. There should be connectivity between the hadoop node running nagios server and the management station. The snmptrap +command will use 162/udp to send trap to the management station. + +Instructions: +------------- +1. Copy the file src/nagios/objects/snmp-commands.cfg to {nagios\_home\_dir}/objects/snmp-commands.cfg in the node where nagios is running. +This file defines the command to send traps for service and host failures. + + The default home directory (nagios_home_dir) for nagios is /etc/nagios + +2. Copy the file src/nagios/objects/snmp-contacts.cfg to {nagios\_home\_dir}/objects/snmp-contacts.cfg in the node where nagios is running. +This file defines the **snmp-management-station** contact. + +3. In the node where ambari-server is running, edit file /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/NAGIOS/package/templates/nagios.cfg.j2 +and add below lines just before the {{nagios\_host\_cfg}} + +
#Definitions for SNMP traps
+	cfg_file=/etc/nagios/objects/snmp-commands.cfg
+	cfg_file=/etc/nagios/objects/snmp-contacts.cfg
+ + Note: If the home directory is different than /etc/nagios, use the updated home directory. The updated configuration will be automatically + pushed to the nagios server when ambari-server restarted. + +4. To enable SNMP trap, edit file /var/lib/ambari-server/resources/stacks/HDP/2.0.6/services/NAGIOS/package/templates/contacts.cfg.j2 +in the ambari-server and add **snmp-management-station** to the contract group **admins** + + > members {{nagios\_web\_login}},sys_logger,**snmp-management-station** + +5. Copy the file src/scripts/send-service-trap to /usr/local/bin/send-service-trap in the node where nagios is running. +Also, run the following command + + > chmod +x /usr/local/bin/send-service-trap + + > chown nagios:nagios /usr/local/bin/send-service-trap + +6. Copy the file src/scripts/send-host-trap to /usr/local/bin/send-host-trap in the node where nagios is running. +Also, run the following command + + > chmod +x /usr/local/bin/send-service-trap + + > chown nagios:nagios /usr/local/bin/send-service-trap + +7. Download nagios MIBS from *http://ftp.cc.uoc.gr/mirrors/monitoring-plugins/mib/nagiosmib-1.0.0.tar.gz* and +extract the files to /usr/share/snmp/mibs/ directory. + +8. Restart ambari-server + > ambari-server restart + +9. Launch ambari-web (or GUI) in the browser and login. Select Nagios server and restart the service. + +10. Configure management station by editing file /etc/hosts and add the below line + + snmp-manager + +11. For integrating with existing management station or NMS system, + 1. Download the nagios MIB's from *http://ftp.cc.uoc.gr/mirrors/monitoring-plugins/mib/nagiosmib-1.0.0.tar.gz* + 2. Extract and copy the files under MIB directory of the management station's (or NMS) mib directory. + 3. Import the mibs if required. + +Testing: +------- +To test whether the snmptraps are triggered, use the following procedure. + +1. Load the MIB in the snmp management system. +2. Make sure the snmp management system IP (or FQDN) is configured in the /etc/hosts file in the node where +nagios server is running. +3. Open the ambari-web in the browser and login. Try to stop some services from ambari-web and check the snmptraps +are received by the snmp management station. diff --git a/contrib/nagios-snmp/src/nagios/objects/snmp-commands.cfg b/contrib/nagios-snmp/src/nagios/objects/snmp-commands.cfg new file mode 100644 index 00000000000..81087bf6f61 --- /dev/null +++ b/contrib/nagios-snmp/src/nagios/objects/snmp-commands.cfg @@ -0,0 +1,33 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# +# + +# 'send-service-trap' command definition +define command { + command_name send-service-trap + command_line /usr/local/bin/send-service-trap snmp-manager public "$HOSTNAME$" "$SERVICEDESC$" $SERVICESTATEID$ "$SERVICEOUTPUT$" +} + +# 'send-host-trap' command definition +define command { + command_name send-host-trap + command_line /usr/local/bin/send-host-trap snmp-manager public "$HOSTNAME$" $HOSTSTATEID$ "$HOSTOUTPUT$" +} diff --git a/contrib/nagios-snmp/src/nagios/objects/snmp-contacts.cfg b/contrib/nagios-snmp/src/nagios/objects/snmp-contacts.cfg new file mode 100644 index 00000000000..cf44858f6ff --- /dev/null +++ b/contrib/nagios-snmp/src/nagios/objects/snmp-contacts.cfg @@ -0,0 +1,31 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# +# + +define contact { + contact_name snmp-management-station + use generic-contact + alias Management Station + service_notification_options w,u,c,r + host_notification_options d,u,r + service_notification_commands send-service-trap + host_notification_commands send-host-trap +} diff --git a/contrib/nagios-snmp/src/scripts/send-host-trap b/contrib/nagios-snmp/src/scripts/send-host-trap new file mode 100644 index 00000000000..388cc6fb228 --- /dev/null +++ b/contrib/nagios-snmp/src/scripts/send-host-trap @@ -0,0 +1,29 @@ +#!/bin/sh +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +# +# Inputs: +# $1 - Management station host name (example: snmp-manager). +# $2 - Community string (example: public, default, etc.,). +# $3 - Host name where the trap originated. +# $4 - Current state of the host (0=UP, 1=DOWN, 2=UNREACHABLE) +# $5 - Host specific description +# +# For more details, refer to NAGIOS-ROOT-MIB.txt and NAGIOS-NOTIFY-MIB.txt +# + +# Sending trap to the management station +/usr/bin/snmptrap -v 2c -c $2 $1 '' NAGIOS-NOTIFY-MIB::nHostEvent nHostname s "$3" nHostStateID i $4 nHostOutput s "$5" diff --git a/contrib/nagios-snmp/src/scripts/send-service-trap b/contrib/nagios-snmp/src/scripts/send-service-trap new file mode 100644 index 00000000000..fc7ffe43b3d --- /dev/null +++ b/contrib/nagios-snmp/src/scripts/send-service-trap @@ -0,0 +1,30 @@ +#!/bin/sh +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License + +# +# Inputs: +# $1 - Management station host name (example: snmp-manager). +# $2 - Community string (example: public, default, etc.,). +# $3 - Host name where the trap originated. +# $4 - Description of the service. +# $5 - Severity ( 0=OK, 1=WARNING, 2=CRITICAL, 3=UNKNOWN). +# $6 - Service specific description. +# +# For more details, refer to NAGIOS-ROOT-MIB.txt and NAGIOS-NOTIFY-MIB.txt +# + +# Sending trap to the management station +/usr/bin/snmptrap -v 2c -c $2 $1 '' NAGIOS-NOTIFY-MIB::nSvcEvent nSvcHostname s "$3" nSvcDesc s "$4" nSvcStateID i $5 nSvcOutput s "$6"