Repository: ambari
Updated Branches:
refs/heads/trunk ef7b9aa29 -> 77281dd58
AMBARI-13205 SNMP MIB for Alerts (Paul Codding via dsen)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/77281dd5
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/77281dd5
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/77281dd5
Branch: refs/heads/trunk
Commit: 77281dd5826ce8860c26c8b79b3afe5e30832414
Parents: ef7b9aa
Author: Dmytro Sen <dsen@apache.org>
Authored: Thu Oct 8 16:20:44 2015 +0300
Committer: Dmytro Sen <dsen@apache.org>
Committed: Thu Oct 8 16:20:44 2015 +0300
----------------------------------------------------------------------
contrib/alert-snmp-mib/APACHE-AMBARI-MIB.txt | 206 ++++++++++++++++++++++
contrib/alert-snmp-mib/README.md | 73 ++++++++
contrib/alert-snmp-mib/snmp_mib_script.sh | 35 ++++
3 files changed, 314 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/77281dd5/contrib/alert-snmp-mib/APACHE-AMBARI-MIB.txt
----------------------------------------------------------------------
diff --git a/contrib/alert-snmp-mib/APACHE-AMBARI-MIB.txt b/contrib/alert-snmp-mib/APACHE-AMBARI-MIB.txt
new file mode 100644
index 0000000..85ec3cd
--- /dev/null
+++ b/contrib/alert-snmp-mib/APACHE-AMBARI-MIB.txt
@@ -0,0 +1,206 @@
+-- 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.
+
+
+APACHE-AMBARI-MIB DEFINITIONS ::= BEGIN
+
+IMPORTS
+ MODULE-IDENTITY, OBJECT-TYPE, NOTIFICATION-TYPE, Integer32, enterprises
+ FROM SNMPv2-SMI
+ MODULE-COMPLIANCE, OBJECT-GROUP, NOTIFICATION-GROUP
+ FROM SNMPv2-CONF
+ TEXTUAL-CONVENTION
+ FROM SNMPv2-TC
+ ;
+
+apacheAmbari MODULE-IDENTITY
+ LAST-UPDATED "201508310000Z"
+ ORGANIZATION "ambari.apache.org"
+ CONTACT-INFO
+ "email: user@ambari.apache.org"
+ DESCRIPTION
+ "Apache Ambari MIB Module"
+ -- Revisions
+ REVISION "201508310000Z"
+ DESCRIPTION
+ "First Apache Ambari MIB"
+ ::= { apache 16 }
+
+apache OBJECT IDENTIFIER ::= { enterprises 18060 }
+apacheAmbariTraps OBJECT IDENTIFIER ::= { apacheAmbari 0 }
+apacheAmbariAlerts OBJECT IDENTIFIER ::= { apacheAmbari 1 }
+
+AlertStateType ::= TEXTUAL-CONVENTION
+ STATUS current
+ DESCRIPTION
+ "A string indicating the state of the Alert."
+ SYNTAX INTEGER {
+ ok(0),
+ unknown(1),
+ warning(2),
+ critical(3)
+ }
+
+apacheAmbariAlertTable OBJECT-TYPE
+ SYNTAX SEQUENCE OF AlertEntry
+ MAX-ACCESS not-accessible
+ STATUS current
+ DESCRIPTION
+ "Table of Apache Ambari Alerts"
+ ::= { apacheAmbariAlerts 1 }
+
+AlertEntry ::= SEQUENCE {
+ alertDefinitionId Integer32,
+ alertDefinitionName OCTET STRING,
+ alertDefinitionHash OCTET STRING,
+ alertName OCTET STRING,
+ alertText OCTET STRING,
+ alertState AlertStateType,
+ alertHost OCTET STRING,
+ alertService OCTET STRING,
+ alertComponent OCTET STRING
+ }
+
+apacheAmbariAlertEntry OBJECT-TYPE
+ SYNTAX AlertEntry
+ MAX-ACCESS not-accessible
+ STATUS current
+ DESCRIPTION
+ "Each Alert Event"
+ INDEX { alertDefinitionId }
+ ::= { apacheAmbariAlertTable 1 }
+
+alertDefinitionId OBJECT-TYPE
+ SYNTAX Integer32 (-2147483648..2147483647)
+ MAX-ACCESS not-accessible
+ STATUS current
+ DESCRIPTION
+ "ID of the Alert"
+ ::= { apacheAmbariAlertEntry 1 }
+
+alertDefinitionName OBJECT-TYPE
+ SYNTAX OCTET STRING
+ MAX-ACCESS accessible-for-notify
+ STATUS current
+ DESCRIPTION
+ "Alert Definition Name"
+ ::= { apacheAmbariAlertEntry 2 }
+
+alertDefinitionHash OBJECT-TYPE
+ SYNTAX OCTET STRING
+ MAX-ACCESS accessible-for-notify
+ STATUS current
+ DESCRIPTION
+ "Alert Definition Hash"
+ ::= { apacheAmbariAlertEntry 3 }
+
+alertName OBJECT-TYPE
+ SYNTAX OCTET STRING
+ MAX-ACCESS accessible-for-notify
+ STATUS current
+ DESCRIPTION
+ "Name of the Alert"
+ ::= { apacheAmbariAlertEntry 4 }
+
+alertText OBJECT-TYPE
+ SYNTAX OCTET STRING
+ MAX-ACCESS accessible-for-notify
+ STATUS current
+ DESCRIPTION
+ "Text output of the Alert"
+ ::= { apacheAmbariAlertEntry 5 }
+
+alertState OBJECT-TYPE
+ SYNTAX AlertStateType
+ MAX-ACCESS accessible-for-notify
+ STATUS current
+ DESCRIPTION
+ "Severity of the Alert"
+ ::= { apacheAmbariAlertEntry 6 }
+
+alertHost OBJECT-TYPE
+ SYNTAX OCTET STRING
+ MAX-ACCESS accessible-for-notify
+ STATUS current
+ DESCRIPTION
+ "Affected Host"
+ ::= { apacheAmbariAlertEntry 7 }
+
+alertService OBJECT-TYPE
+ SYNTAX OCTET STRING
+ MAX-ACCESS accessible-for-notify
+ STATUS current
+ DESCRIPTION
+ "Affected Service"
+ ::= { apacheAmbariAlertEntry 8 }
+
+alertComponent OBJECT-TYPE
+ SYNTAX OCTET STRING
+ MAX-ACCESS accessible-for-notify
+ STATUS current
+ DESCRIPTION
+ "Affected Component"
+ ::= { apacheAmbariAlertEntry 9 }
+
+apacheAmbariAlert NOTIFICATION-TYPE
+ OBJECTS {
+ alertDefinitionName, alertDefinitionHash,
+ alertName, alertText, alertState, alertHost, alertService,
+ alertComponent
+ }
+ STATUS current
+ DESCRIPTION
+ "The SNMP trap that is generated as a result of an alert."
+ ::= { apacheAmbariTraps 1 }
+
+apacheAmbariConformance OBJECT IDENTIFIER ::=
+ { apacheAmbariAlerts 3 }
+apacheAmbariCompliances OBJECT IDENTIFIER ::=
+ { apacheAmbariConformance 1 }
+apacheAmbariConformanceGroups OBJECT IDENTIFIER ::=
+ { apacheAmbariConformance 2 }
+
+apacheAmbariMIBCompliance MODULE-COMPLIANCE
+ STATUS current
+ DESCRIPTION
+ "Compliance statement for entities which implement this MIB."
+ MODULE
+ MANDATORY-GROUPS {
+ apacheAmbariAlertGroup,
+ apacheAmbariAlertObjectGroup
+ }
+ ::= { apacheAmbariCompliances 2 }
+
+apacheAmbariAlertGroup NOTIFICATION-GROUP
+ NOTIFICATIONS {
+ apacheAmbariAlert
+ }
+ STATUS current
+ DESCRIPTION
+ "Notification objects."
+ ::= { apacheAmbariConformanceGroups 2 }
+
+apacheAmbariAlertObjectGroup OBJECT-GROUP
+ OBJECTS {
+ alertDefinitionName, alertDefinitionHash,
+ alertName, alertText, alertState, alertHost, alertService,
+ alertComponent
+ }
+ STATUS current
+ DESCRIPTION
+ "Event Objects"
+ ::= { apacheAmbariConformanceGroups 3 }
+END
http://git-wip-us.apache.org/repos/asf/ambari/blob/77281dd5/contrib/alert-snmp-mib/README.md
----------------------------------------------------------------------
diff --git a/contrib/alert-snmp-mib/README.md b/contrib/alert-snmp-mib/README.md
new file mode 100644
index 0000000..37fbc0a
--- /dev/null
+++ b/contrib/alert-snmp-mib/README.md
@@ -0,0 +1,73 @@
+<!---
+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.
+-->
+
+## SNMP MIB and Script Extension
+
+This extension is meant to be used with Ambari 2.1 or later and uses the capabilities introduced
in AMBARI-9919 to delegate alerts to an external script.
+
+In this case, the external script `snmp_mib_script.sh` is used to invoke the `snmptrap` command
from the `net-snmp` Linux packages to issue an SNMP trap to a specific destination.
+
+In order to wire this script up to Ambari the following procedures should be followed as
the root user, or with a user with equivalent sudo access:
+
+Install SNMP Utils
+
+ yum install net-snmp net-snmp-utils net-snmp-libs -y
+
+Make SNMP Utils aware of the Apache Ambari MIB
+
+ cp APACHE-AMBARI-MIB.txt /usr/share/snmp/mibs
+
+Startup a simple SNMP trap daemon to log all traps to the `/tmp/traps.log` file for testing
purposes.
+
+ nohup snmptrapd -m ALL -A -n -Lf /tmp/traps.log &
+
+Invoke a test trap to ensure that the snmptrapd is logging appropriately to `/tmp/traps.log`
and the Apache Ambari MIB is being respected.
+
+ snmptrap -v 2c -c public localhost '' APACHE-AMBARI-MIB::apacheAmbariAlert alertDefinitionName
s "definitionName" alertDefinitionHash s "definitionHash" alertName s "name" alertText s "text"
alertState i 0 alertHost s "host" alertService s "service" alertComponent s "component"
+
+You should see this in /tmp/traps.log.
+
+ 2015-09-03 05:14:30 UDP: [127.0.0.1]:45431->[127.0.0.1] [UDP: [127.0.0.1]:45431->[127.0.0.1]]:
+ DISMAN-EVENT-MIB::sysUpTimeInstance = Timeticks: (15638958) 1 day, 19:26:29.58 SNMPv2-MIB::snmpTrapOID.0
= OID: APACHE-AMBARI-MIB::apacheAmbariAlert APACHE-AMBARI-MIB::alertDefinitionName = STRING:
"definitionName" APACHE-AMBARI-MIB::alertDefinitionHash = STRING: "definitionHash" APACHE-AMBARI-MIB::alertName
= STRING: "name" APACHE-AMBARI-MIB::alertText = STRING: "text" APACHE-AMBARI-MIB::alertState
= INTEGER: ok(0) APACHE-AMBARI-MIB::alertHost = STRING: "host" APACHE-AMBARI-MIB::alertService
= STRING: "service" APACHE-AMBARI-MIB::alertComponent = STRING: "component"
+
+Once that output has been validated, it's time to make Ambari aware of the script to begin
sending SNMP traps that conform to it.
+
+Create a file that contains the script, named `/tmp/snmp_mib_script.sh`, in this example.
It's recommended to create this file in a more permanent directory for actual use.
+
+Add the following line to the `/etc/ambari-server/conf/ambari.properties` file
+
+ org.apache.ambari.contrib.snmp.script=/tmp/snmp_mib_script.sh
+
+Restart Ambari using `ambari-server restart`
+
+Now, we need to use the API to add an alert target for this script. The following content
needs to be POST'd to /api/v1/alert_targets.
+
+ {
+ "AlertTarget": {
+ "name": "SNMP_MIB",
+ "description": "SNMP MIB Target",
+ "notification_type": "ALERT_SCRIPT",
+ "global": true,
+ "properties": {
+ "ambari.dispatch-property.script": "org.apache.ambari.contrib.snmp.script"
+ }
+ }
+ }
+
+You'll notice the link between the alert target and the script is this property reference:
`org.apache.ambari.contrib.snmp.script`.
+
+At this point each alert will send an SNMP trap to the local trap daemon and an entry will
be recorded in `/tmp/traps.log`.
http://git-wip-us.apache.org/repos/asf/ambari/blob/77281dd5/contrib/alert-snmp-mib/snmp_mib_script.sh
----------------------------------------------------------------------
diff --git a/contrib/alert-snmp-mib/snmp_mib_script.sh b/contrib/alert-snmp-mib/snmp_mib_script.sh
new file mode 100644
index 0000000..a46dd13
--- /dev/null
+++ b/contrib/alert-snmp-mib/snmp_mib_script.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# 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.
+#
+
+HOST=localhost
+COMMUNITY=public
+
+STATE=0
+if [ $4 == "OK" ]; then
+ STATE=0
+elif [ $4 == "UNKNOWN" ]; then
+ STATE=1
+elif [ $4 == "WARNING" ]; then
+ STATE=2
+elif [ $4 == "CRITICAL" ]; then
+ STATE=3
+fi
+
+/usr/bin/snmptrap -v 2c -c $COMMUNITY $HOST '' APACHE-AMBARI-MIB::apacheAmbariAlert alertDefinitionName
s "$1" alertName s "$2" alertText s "$5" alertState i $STATE alertService s "$3"
|