mooli tayer has uploaded a new change for review. Change subject: notifier: modify the oid schema for SNMP notification. ......................................................................
notifier: modify the oid schema for SNMP notification. Note: this is a temporary location for MIB files. They pass syntax check using: $ smilint -p ./REDHAT-MIB.txt -l 6 ./OVIRT-MIB.txt Change-Id: Ic8a06063f8ebbbe4d05783cb25036e870a6be3b7 Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1136818 Signed-off-by: Mooli Tayer <[email protected]> --- M backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/snmp/Snmp.java A backend/manager/tools/src/main/resources/mib/OVIRT-MIB.txt A backend/manager/tools/src/main/resources/mib/REDHAT-MIB.txt M packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in 4 files changed, 435 insertions(+), 63 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/51/32951/1 diff --git a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/snmp/Snmp.java b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/snmp/Snmp.java index ec62f97..c3acdc7 100644 --- a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/snmp/Snmp.java +++ b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/transport/snmp/Snmp.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.net.InetAddress; +import java.text.SimpleDateFormat; import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -13,6 +14,7 @@ import org.apache.log4j.Logger; import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.EventNotificationMethod; +import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.notifier.NotificationServiceException; import org.ovirt.engine.core.notifier.dao.DispatchResult; import org.ovirt.engine.core.notifier.filter.AuditLogEvent; @@ -20,7 +22,9 @@ import org.ovirt.engine.core.notifier.utils.NotificationProperties; import org.snmp4j.CommunityTarget; import org.snmp4j.PDU; +import org.snmp4j.Target; import org.snmp4j.mp.SnmpConstants; +import org.snmp4j.smi.Integer32; import org.snmp4j.smi.OID; import org.snmp4j.smi.OctetString; import org.snmp4j.smi.TimeTicks; @@ -35,10 +39,11 @@ private static final String SNMP_MANAGERS = "SNMP_MANAGERS"; private static final String SNMP_COMMUNITY = "SNMP_COMMUNITY"; private static final String SNMP_OID = "SNMP_OID"; - private static final int ENTERPRISE_SPECIFIC = 6; private static final Pattern PROFILE_PATTERN = Pattern.compile(SNMP_MANAGERS + "(|_(?<profile>.*))"); private final Map<String, Profile> profiles = new HashMap<>(); + + private static final SimpleDateFormat ISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); private org.snmp4j.Snmp snmp = null; private boolean active = false; private static long nanoStart = System.nanoTime(); @@ -97,66 +102,10 @@ // PDU class is for SNMPv2c units PDU v2pdu = new PDU(); v2pdu.setType(PDU.TRAP); - int auditLogTypeVal = AuditLogType.UNASSIGNED.getValue(); - try { - // TODO mtayer: what about db? add to audit log type - auditLogTypeVal = AuditLogType.valueOf(event.getName()).getValue(); - } catch (IllegalArgumentException e) { - log.warn("Could not find event: " + event.getName() + " in auditLogTypes"); - } - OID trapOID = SnmpConstants.getTrapOID(profile.oid, ENTERPRISE_SPECIFIC, auditLogTypeVal); - v2pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, trapOID)); - v2pdu.add(new VariableBinding(SnmpConstants.sysUpTime, - new TimeTicks((System.nanoTime() - nanoStart) / 10000000))); - v2pdu.add(new VariableBinding( - new OID(trapOID).append(0), - new OctetString(event.getMessage()))); - v2pdu.add(new VariableBinding( - new OID(trapOID).append(1), - new OctetString(event.getSeverity().name()))); - v2pdu.add(new VariableBinding( - new OID(trapOID).append(2), - new OctetString(event.getType().name()))); - v2pdu.add(new VariableBinding( - new OID(trapOID).append(3), - new OctetString(event.getLogTime().toString()))); - v2pdu.add(new VariableBinding( - new OID(trapOID).append(4), - new OctetString(event.getLogTypeName()))); - if (!StringUtils.isEmpty(event.getUserName())) { - v2pdu.add(new VariableBinding( - new OID(trapOID).append(5), - new OctetString(event.getUserName()))); - } - if (!StringUtils.isEmpty(event.getVmName())) { - v2pdu.add(new VariableBinding( - new OID(trapOID).append(6), - new OctetString(event.getVmName()))); - } - if (!StringUtils.isEmpty(event.getVdsName())) { - v2pdu.add(new VariableBinding( - new OID(trapOID).append(7), - new OctetString(event.getVdsName()))); - } - if (!StringUtils.isEmpty(event.getVmTemplateName())) { - v2pdu.add(new VariableBinding( - new OID(trapOID).append(8), - new OctetString(event.getVmTemplateName()))); - } - if (!StringUtils.isEmpty(event.getStoragePoolName())) { - v2pdu.add(new VariableBinding( - new OID(trapOID).append(9), - new OctetString(event.getStoragePoolName()))); - } - if (!StringUtils.isEmpty(event.getStorageDomainName())) { - v2pdu.add(new VariableBinding( - new OID(trapOID).append(10), - new OctetString(event.getStorageDomainName()))); - } - CommunityTarget target = new CommunityTarget(); - target.setCommunity(profile.community); - target.setVersion(SnmpConstants.version2c); + addPayload(v2pdu, event, profile); + + Target target = createTarget(profile); for (Host host : profile.hosts) { try { log.info(String.format("Generate an snmp trap for event: %s to address: %s ", @@ -176,6 +125,112 @@ } } + private CommunityTarget createTarget(Profile profile) { + CommunityTarget target = new CommunityTarget(); + target.setCommunity(profile.community); + target.setVersion(SnmpConstants.version2c); + return target; + } + + private void addPayload(PDU v2pdu, AuditLogEvent event, Profile profile) { + + // { [baseoid] notifications(1) compliance(0) audit(1) } + v2pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, + new OID(profile.oid).append(1).append(0).append(1))); + v2pdu.add(new VariableBinding(SnmpConstants.sysUpTime, + new TimeTicks((System.nanoTime() - nanoStart) / 10000000))); + + int auditLogId = AuditLogType.UNASSIGNED.getValue(); + try { + auditLogId = AuditLogType.valueOf(event.getName()).getValue(); + } catch (IllegalArgumentException e) { + log.warn("Could not find event: " + event.getName() + " in auditLogTypes"); + } + // { [baseoid] objects(2) audit(1) } + OID auditObjects = new OID(profile.oid).append(2).append(1); + + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(1), + new OctetString(event.getName()))); + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(2), + new Integer32(auditLogId))); + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(3), + new Integer32(event.getSeverity().getValue()))); + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(4), + new OctetString(event.getMessage()))); + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(5), + new Integer32(event.getType().getValue()))); + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(6), + new OctetString(ISO8601.format(event.getLogTime())))); + + // Optional pdu: + if (!StringUtils.isEmpty(event.getUserName())) { + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(7), + new OctetString(event.getUserName()))); + } + if (event.getUserId() != null && !event.getUserId().equals(Guid.Empty)) { + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(8), + new OctetString(event.getUserId().toString()))); + } + if (!StringUtils.isEmpty(event.getVmName())) { + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(9), + new OctetString(event.getVmName()))); + } + if (event.getVmId() != null && !event.getVmId().equals(Guid.Empty)) { + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(10), + new OctetString(event.getVmId().toString()))); + } + if (!StringUtils.isEmpty(event.getVdsName())) { + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(11), + new OctetString(event.getVdsName()))); + } + if (event.getVdsId() != null && !event.getVdsId().equals(Guid.Empty)) { + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(12), + new OctetString(event.getVdsId().toString()))); + } + if (!StringUtils.isEmpty(event.getVmTemplateName())) { + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(13), + new OctetString(event.getVmTemplateName()))); + } + if (event.getVmTemplateId() != null && !event.getVmTemplateId().equals(Guid.Empty)) { + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(14), + new OctetString(event.getVmTemplateId().toString()))); + } + if (!StringUtils.isEmpty(event.getStoragePoolName())) { + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(15), + new OctetString(event.getStoragePoolName()))); + } + if (event.getStoragePoolId() != null && !event.getStoragePoolId().equals(Guid.Empty)) { + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(16), + new OctetString(event.getStoragePoolId().toString()))); + } + if (!StringUtils.isEmpty(event.getStorageDomainName())) { + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(17), + new OctetString(event.getStorageDomainName()))); + } + if (event.getStorageDomainId() != null && !event.getStorageDomainId().equals(Guid.Empty)) { + v2pdu.add(new VariableBinding( + new OID(auditObjects).append(18), + new OctetString(event.getStorageDomainId().toString()))); + } + } + private static class Host { public String name; public int port = 162; diff --git a/backend/manager/tools/src/main/resources/mib/OVIRT-MIB.txt b/backend/manager/tools/src/main/resources/mib/OVIRT-MIB.txt new file mode 100644 index 0000000..78c774f --- /dev/null +++ b/backend/manager/tools/src/main/resources/mib/OVIRT-MIB.txt @@ -0,0 +1,284 @@ + +-- +-- Copyright 2014 Red Hat Inc. +-- +-- Licensed 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. +-- + +OVIRT-MIB DEFINITIONS ::= BEGIN + +IMPORTS + Integer32, + MODULE-IDENTITY, + NOTIFICATION-TYPE, + OBJECT-TYPE FROM SNMPv2-SMI + NOTIFICATION-GROUP, + MODULE-COMPLIANCE, + OBJECT-GROUP FROM SNMPv2-CONF + redhat FROM REDHAT-MIB +; + +ovirt MODULE-IDENTITY + LAST-UPDATED "201409140000Z" + ORGANIZATION "www.ovirt.org" + CONTACT-INFO "TBD" + DESCRIPTION "TBD" + REVISION "201409140000Z" + DESCRIPTION + "First draft" + ::= { redhat 13} + +-- +-- top level structure +-- +ovirtEngine OBJECT IDENTIFIER ::= { ovirt 1 } +ovirtEngineNotifier OBJECT IDENTIFIER ::= { ovirtEngine 1 } + +ovirtEngineNotifierNotifications OBJECT IDENTIFIER ::= { ovirtEngineNotifier 1 } + +ovirtEngineNotifierObjects OBJECT IDENTIFIER ::= { ovirtEngineNotifier 2 } +ovirtEngineNotifierObjectsAudit OBJECT IDENTIFIER ::= { ovirtEngineNotifierObjects 1 } + +ovirtEngineNotifierGroups OBJECT IDENTIFIER ::= { ovirtEngineNotifier 3 } + +ovirtEngineNotifierCompliances OBJECT IDENTIFIER ::= { ovirtEngineNotifier 4 } + +-- +-- Compliance +-- + +ovirtEngineNotifierCompliance MODULE-COMPLIANCE + STATUS current + DESCRIPTION + "MANDATORY-GROUPS must be implemented to comply with this module." + MODULE -- this module + MANDATORY-GROUPS { ovirtEngineNotificationsGroup, ovirtEngineObjectAuditGroup } + ::= { ovirtEngineNotifierCompliances 2 } + + +-- +-- Trap definition +-- + +ovirtEngineNotificationsGroup NOTIFICATION-GROUP + NOTIFICATIONS { ovirtEngineNotifierNotificationsComplianceAudit } + STATUS current + DESCRIPTION "A group for the single notification type ovirtEngineNotifierNotificationsAudit + defined since every notification defined in an SMIv2 module is required to be + listed in at least one group in order to be conformant." +::= { ovirtEngineNotifierGroups 1 } + +ovirtEngineNotifierNotificationsCompliance OBJECT IDENTIFIER ::= { ovirtEngineNotifierNotifications 0 } + +ovirtEngineNotifierNotificationsComplianceAudit NOTIFICATION-TYPE + OBJECTS { + ovirtEngineNotifierName, + ovirtEngineNotifierId, + ovirtEngineNotifierSeverity, + ovirtEngineNotifierMessage, + ovirtEngineNotifierStatus, + ovirtEngineNotifierDatetime + } + STATUS current + DESCRIPTION + "Defines an audit log event sent by ovirt-engine-notifier. + Mandatory object are also defined here" +::= { ovirtEngineNotifierNotificationsCompliance 1 } + +-- +-- Objects +-- +ovirtEngineObjectAuditGroup OBJECT-GROUP + OBJECTS { + ovirtEngineNotifierName, + ovirtEngineNotifierId, + ovirtEngineNotifierSeverity, + ovirtEngineNotifierMessage, + ovirtEngineNotifierStatus, + ovirtEngineNotifierDatetime, + ovirtEngineNotifierUsername, + ovirtEngineNotifierUserId, + ovirtEngineNotifierVmName, + ovirtEngineNotifierVmId, + ovirtEngineNotifierHostName, + ovirtEngineNotifierHostId, + ovirtEngineNotifierTemplateName, + ovirtEngineNotifierTemplateId, + ovirtEngineNotifierStoragePoolName, + ovirtEngineNotifierStoragePoolId, + ovirtEngineNotifierStorageDomainName, + ovirtEngineNotifierStorageDomainId + } + STATUS current + DESCRIPTION "A group for all mandatory and optional objects sent in + ovirtEngineNotifierNotificationsAudit notifications. + defined since every defined in an SMIv2 module is required to be + listed in at least one group in order to be conformant " +::= { ovirtEngineNotifierGroups 2 } + +ovirtEngineNotifierName OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The name of the audit event, e,g VDC_STOP. + See AuditLogMessages.properties." +::= { ovirtEngineNotifierObjectsAudit 1 } + +ovirtEngineNotifierId OBJECT-TYPE + SYNTAX Integer32 + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The id of the audit event, e,g 2." +::= { ovirtEngineNotifierObjectsAudit 2 } + +ovirtEngineNotifierSeverity OBJECT-TYPE + SYNTAX INTEGER { + normal (0), + warning( 1), + error (2), + alert (10) + } + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The severity of the audit event." +::= { ovirtEngineNotifierObjectsAudit 3 } + +ovirtEngineNotifierMessage OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The text message associated with the audit event." +::= { ovirtEngineNotifierObjectsAudit 4 } + +ovirtEngineNotifierStatus OBJECT-TYPE + SYNTAX INTEGER { + resolveMessage (0), + alertMessage (1) + } + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The lifecycle status of this audit log event." +::= { ovirtEngineNotifierObjectsAudit 5 } + +ovirtEngineNotifierDatetime OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The Datetime of the audit event occurred as ISO 8601 (yyyy-MM-dd'T'HH:mm'Z')." +::= { ovirtEngineNotifierObjectsAudit 6 } + +-- optional pdu: + +ovirtEngineNotifierUsername OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The Username associated with the audit event(optional)." +::= { ovirtEngineNotifierObjectsAudit 7 } + +ovirtEngineNotifierUserId OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The uuid associated with the audit event(optional)." +::= { ovirtEngineNotifierObjectsAudit 8 } + +ovirtEngineNotifierVmName OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The name of the vm associated with the audit event(optional)." +::= { ovirtEngineNotifierObjectsAudit 9 } + +ovirtEngineNotifierVmId OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The uuid of the vm associated with the audit event(optional)." +::= { ovirtEngineNotifierObjectsAudit 10 } + +ovirtEngineNotifierHostName OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The name of the host associated with the audit event(optional)." +::= { ovirtEngineNotifierObjectsAudit 11 } + +ovirtEngineNotifierHostId OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The uuid of the host associated with the audit event(optional)." +::= { ovirtEngineNotifierObjectsAudit 12 } + +ovirtEngineNotifierTemplateName OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The name of the template associated with the audit event(optional)." +::= { ovirtEngineNotifierObjectsAudit 13 } + +ovirtEngineNotifierTemplateId OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The uuid of the template associated with the audit event(optional)." +::= { ovirtEngineNotifierObjectsAudit 14 } + +ovirtEngineNotifierStoragePoolName OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The name of the storage pool associated with the audit event(optional)." +::= { ovirtEngineNotifierObjectsAudit 15 } + +ovirtEngineNotifierStoragePoolId OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The uuid of the storage pool associated with the audit event(optional)." +::= { ovirtEngineNotifierObjectsAudit 16 } + +ovirtEngineNotifierStorageDomainName OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The name of the storage domain associated with the audit event(optional)." +::= { ovirtEngineNotifierObjectsAudit 17 } + +ovirtEngineNotifierStorageDomainId OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS accessible-for-notify + STATUS current + DESCRIPTION + "The uuid of the storage domain associated with the audit event(optional)." +::= { ovirtEngineNotifierObjectsAudit 18 } + +END diff --git a/backend/manager/tools/src/main/resources/mib/REDHAT-MIB.txt b/backend/manager/tools/src/main/resources/mib/REDHAT-MIB.txt new file mode 100644 index 0000000..0de8d28 --- /dev/null +++ b/backend/manager/tools/src/main/resources/mib/REDHAT-MIB.txt @@ -0,0 +1,33 @@ +-- +-- Copyright 2014 Red Hat Inc. +-- +-- Licensed 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. +-- + +REDHAT-MIB DEFINITIONS ::= BEGIN + +IMPORTS + MODULE-IDENTITY, enterprises FROM SNMPv2-SMI +; + +redhat MODULE-IDENTITY + LAST-UPDATED "201409140000Z" + ORGANIZATION "www.redhat.org" + CONTACT-INFO "TBD" + DESCRIPTION "TBD" + REVISION "201409140000Z" + DESCRIPTION + "First draft" + ::= { enterprises 2312} + +END diff --git a/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in b/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in index 1cdbe24..03ec3d7 100644 --- a/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in +++ b/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in @@ -152,10 +152,10 @@ # Default SNMP Community String. SNMP_COMMUNITY=public -# Default TRAP Object Identifier for alerts. +# SNMP Trap Object Identifier for outgoing notifications. +# { iso(1) org(3) dod(6) internet(1) private(4) enterprises(1) redhat(2312) ovirt(13) engine(1) notifier(1) } # -# iso.organization.DoD.Internet.private.enterprises.redhat.ovirt-engine.notifications.audit-log -# 1.3.6.1.4.1.2312.13.1.1 +# Changing the default will prevent generated traps from with complying with OVIRT-MIB.txt SNMP_OID=1.3.6.1.4.1.2312.13.1.1 # -- To view, visit http://gerrit.ovirt.org/32951 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic8a06063f8ebbbe4d05783cb25036e870a6be3b7 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: mooli tayer <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
