User Tools
Writing /app/www/public/data/meta/onboarding/snmpmanager/trap_rule_template.meta failed
onboarding:snmpmanager:trap_rule_template
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| onboarding:snmpmanager:trap_rule_template [2021/04/15 16:14] – 10.91.120.28 | onboarding:snmpmanager:trap_rule_template [2026/01/07 11:10] (current) – 10.91.120.100 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Trap Rule Template ====== | ||
| + | This is a template example for creating trap rules. Trap rules should generally follow the structure laid out in this template with the undefined variables filled in with information from the trap. | ||
| + | Please follow this structure as much as possible for a given technology. The logging guidelines are **very important** for reporting and analysis, so keep the exact text format of the statements annotated with ' | ||
| + | |||
| + | <code groovy> | ||
| + | com.errigal.snmpmanager.Trap trap -> | ||
| + | |||
| + | /* Logging Rule: Output information for Technology and Trap rule name */ | ||
| + | String techName = " | ||
| + | log.info " | ||
| + | |||
| + | com.errigal.snmpmanager.wrapper.TrapWrapper trapWrapper = new com.errigal.snmpmanager.wrapper.TrapWrapper(trap) | ||
| + | |||
| + | /* Extract and Define trap varbind details */ | ||
| + | String trapType = trapWrapper.getVarbind(" | ||
| + | String alarmName = trapWrapper.getVarbind(" | ||
| + | String alarmText = trapWrapper.getVarbind(" | ||
| + | String alarmIdentifier = trapWrapper.getVarbind(" | ||
| + | boolean isClear = //Determine if clear trap | ||
| + | |||
| + | /* Logging Rule: Log Varbinds Of your technology specific Trap */ | ||
| + | log.info "Trap ID-${trap.id}: | ||
| + | log.info "Trap ID-${trap.id}: | ||
| + | log.info "Trap ID-${trap.id}: | ||
| + | log.info "Trap ID-${trap.id}: | ||
| + | |||
| + | com.errigal.snmpmanager.knowledge.DasHub hub | ||
| + | com.errigal.snmpmanager.knowledge.DasHub.withTransaction { | ||
| + | hub = com.errigal.snmpmanager.knowledge.DasHub.findByIpAddress(trap? | ||
| + | if (!hub) { | ||
| + | /* Logging Rule: Output information hub was not found and we are creating an orphan for it */ | ||
| + | log.warn " | ||
| + | com.errigal.snmpmanager.NetworkElement orphans = com.errigal.snmpmanager.NetworkElement.findByName(" | ||
| + | com.errigal.snmpmanager.Technology technology = com.errigal.snmpmanager.Technology.findByName(" | ||
| + | hub = new com.errigal.snmpmanager.knowledge.DasHub( | ||
| + | name: " | ||
| + | neType: " | ||
| + | ipAddress: trap.ipAddress, | ||
| + | onAir: true, | ||
| + | showInMonitor: | ||
| + | technology: " | ||
| + | assignedTechnology: | ||
| + | clusterName: | ||
| + | parent: orphans | ||
| + | ) | ||
| + | orphans.addToChildren(hub) | ||
| + | hub.save(failOnError: | ||
| + | orphans.save(failOnError: | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | String neName = // Determine or parse Node Name If applicable | ||
| + | boolean isHub = false //Assuming it a child element, we are checking soon | ||
| + | |||
| + | if(/* Tech specific determination if Trap Is Hub Trap */) { | ||
| + | log.info "Trap ID-${trap.id}: | ||
| + | alarmingNe = hub | ||
| + | isHub = true | ||
| + | } else { /* Trap Is Child Level */ | ||
| + | /* Logging Rule: Output information for the name of the child element which is being attempted to be looked up under the controller */ | ||
| + | log.info "Trap ID-${trap.id}: | ||
| + | alarmingNe = com.errigal.snmpmanager.wrapper.NetworkElementWrapper.findNetworkElement(hub.name, | ||
| + | } | ||
| + | |||
| + | |||
| + | /* If alarming NE is null here, we could not find a child when we expected to find one */ | ||
| + | if (!alarmingNe) { | ||
| + | /* Logging Rule: Output warning we could not find the element with the string name used */ | ||
| + | log.warn "Trap ID-${trap.id}: | ||
| + | def missingUnitTrap = new com.errigal.snmpmanager.autodiscovery.trap.ErrigalMissingUnitTrap(hub, | ||
| + | missingUnitTrap.send(" | ||
| + | /* Fallback to the Hub and send a device missing trap */ | ||
| + | isHub = true | ||
| + | alarmingNe = hub | ||
| + | /* Logging Rule: Output warning we are falling alarm back to the hub */ | ||
| + | log.warn "Trap ID-${trap.id}: | ||
| + | } | ||
| + | |||
| + | /* Time to process trap to gts at this stage */ | ||
| + | com.errigal.snmpmanager.GeneralTrapSummary gts | ||
| + | com.errigal.snmpmanager.GeneralTrapSummary.withTransaction { | ||
| + | gts = new com.errigal.snmpmanager.GeneralTrapSummary() | ||
| + | /* Logging Rule: Output information GTS creation is in progress */ | ||
| + | log.info "Trap ID-${trap.id}: | ||
| + | gts.trap = trap | ||
| + | gts.trapType = trapType | ||
| + | gts.trapName = trap.name | ||
| + | gts.networkElement = alarmingNe | ||
| + | gts.context = alarmText | ||
| + | gts.clearTrap = isClear | ||
| + | gts.alarmStatus = alarmSeverity | ||
| + | def alarmStatusEnum = com.errigal.snmpmanager.trap.AlarmStatus.resolveFromString(alarmSeverity) | ||
| + | gts.alarmImpacting = alarmStatusEnum ? alarmStatusEnum.isAlarmImpacting() : false | ||
| + | gts.clearReason = isClear ? "Clear Trap Received" | ||
| + | gts.alarmIdentifier = alarmIdentifier | ||
| + | gts.summary = " | ||
| + | gts.save(failOnError: | ||
| + | /* Logging Rule: Output information GTS creation has completed */ | ||
| + | log.info "Trap ID-${trap.id}: | ||
| + | } | ||
| + | |||
| + | /* We need to create new alarm or access an existing alarm if already created previously */ | ||
| + | com.errigal.snmpmanager.wrapper.GeneralTrapSummaryWrapper gtsw = new com.errigal.snmpmanager.wrapper.GeneralTrapSummaryWrapper(gts) | ||
| + | com.errigal.snmpmanager.ActiveAlarm alarm = gtsw.getActiveAlarmWrapper()? | ||
| + | |||
| + | /* If we have a clear, we need to find the alarm corresponsing to the clear */ | ||
| + | if(isClear) { | ||
| + | if(alarm) { | ||
| + | com.errigal.snmpmanager.ActiveAlarm.withTransaction { | ||
| + | com.errigal.snmpmanager.ActiveAlarm activeAlarm = com.errigal.snmpmanager.ActiveAlarm.findById(alarm.id) | ||
| + | activeAlarm.cleared = true | ||
| + | activeAlarm.clearedDate = new Date() | ||
| + | activeAlarm.clearedReason = (gts.getClearReason() ?: "" | ||
| + | activeAlarm.clearingGTS = (com.errigal.snmpmanager.GeneralTrapSummary) gtsw.getDomain() | ||
| + | activeAlarm.previousStatus = activeAlarm.status | ||
| + | activeAlarm.status = " | ||
| + | if (!activeAlarm? | ||
| + | /* Logging Rule: Output error alarm clearing process has failed */ | ||
| + | log.error "Trap ID-${trap.id}: | ||
| + | } else { | ||
| + | /* Logging Rule: Output information that alarm has been cleared */ | ||
| + | log.info "Trap ID-${trap.id}: | ||
| + | int numTickets = activeAlarm.tickets.size() | ||
| + | /* Logging Rule: Output information that ticket clearing process has begun */ | ||
| + | log.info "Trap ID-${trap.id}: | ||
| + | activeAlarm.tickets.each { com.errigal.snmpmanager.RemoteTicket ticket -> | ||
| + | def ticketId = ticket.ticketIdentifier | ||
| + | /* Logging Rule: Output information about which ticket is being cleared */ | ||
| + | log.info "Trap ID-${trap.id}: | ||
| + | com.errigal.shared.remote.RemoteTicketCreator.instance.updateTicket(ticketId, | ||
| + | com.errigal.snmpmanager.TicketerConfiguration.findByName(" | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | } else { /* We have a clear but no alarm for it, it has to be ignored */ | ||
| + | /* Logging Rule: Output warning, we have a clear but no alarm for it, we possibly missed or mishandled the original alarm */ | ||
| + | log.warn "Trap ID-${trap.id}: | ||
| + | } | ||
| + | gtsw.save() | ||
| + | } else { /* We have an alarm which needs a ticket scheduled */ | ||
| + | if ((!alarm || (!alarm? | ||
| + | def ne = gtsw.getDomain().networkElement | ||
| + | def parentNe = (isHub == true) ? ne : ne.parent | ||
| + | String formNeName = (!isHub) ? hub.name + " - " + alarmingNe.name : hub.name | ||
| + | String summaryString = formNeName + ":" | ||
| + | int ticketCreationDelay = 60 | ||
| + | |||
| + | /* Logging Rule: Output information ticket scheduling is in progress for Hub/Child name with given alarm */ | ||
| + | log.info "Trap ID-${trap.id}: | ||
| + | |||
| + | /* In order create a ticket certain values are needed */ | ||
| + | String workflowName = ne.workflow ? ne.workflow : "SNMP Trap" | ||
| + | HashMap < String, String > ticketValues = new HashMap < String, String > () | ||
| + | ticketValues.put(" | ||
| + | ticketValues.put(" | ||
| + | ticketValues.put(" | ||
| + | ticketValues.put(" | ||
| + | ticketValues.put(" | ||
| + | ticketValues.put(" | ||
| + | ticketValues.put(" | ||
| + | |||
| + | /* Value which are needed to add SNMP Trap form to ticket */ | ||
| + | HashMap < String, String > formValues = new HashMap < String, String > () | ||
| + | formValues.put(" | ||
| + | formValues.put(" | ||
| + | formValues.put(" | ||
| + | formValues.put(" | ||
| + | formValues.put(" | ||
| + | formValues.put(" | ||
| + | formValues.put(" | ||
| + | formValues.put(" | ||
| + | formValues.put(" | ||
| + | formValues.put(" | ||
| + | |||
| + | HashMap < String, String > [] formsArray = new HashMap < String, String > [1] | ||
| + | formsArray[0] = formValues | ||
| + | final int TO_SEC = 60 | ||
| + | |||
| + | if (gtsw.getDomain().alarmStatus.equalsIgnoreCase(" | ||
| + | ticketValues.put(" | ||
| + | ticketCreationDelay = 15 | ||
| + | } else if (gtsw.getDomain().alarmStatus.equalsIgnoreCase(" | ||
| + | ticketValues.put(" | ||
| + | ticketCreationDelay = 30 | ||
| + | } else if (gtsw.getDomain().alarmStatus.equalsIgnoreCase(" | ||
| + | ticketValues.put(" | ||
| + | ticketCreationDelay = 60 | ||
| + | } | ||
| + | |||
| + | gtsw.scheduleAlarmAndTicketForLaterWithForms(0, | ||
| + | /* Logging Rule: Output information ticket scheduling is complete */ | ||
| + | log.info "Trap ID-${trap.id}: | ||
| + | } else if (!alarm || !(alarm? | ||
| + | /* Logging Rule: Output information alarm was scheduled with no ticket to be created */ | ||
| + | log.info "Trap ID-${trap.id}: | ||
| + | gtsw.scheduleAlarmForLater(10) | ||
| + | } else { | ||
| + | /* Logging Rule: Output information alarm was marked as repeat */ | ||
| + | log.info "Trap ID-${trap.id}: | ||
| + | } | ||
| + | gtsw.save() | ||
| + | } | ||
| + | </ | ||