Skip to content

Instantly share code, notes, and snippets.

@kylebrandt
Last active October 12, 2017 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylebrandt/536300a5b1d6208394b264736ed76612 to your computer and use it in GitHub Desktop.
Save kylebrandt/536300a5b1d6208394b264736ed76612 to your computer and use it in GitHub Desktop.
Draft of Port-Channel Admin/Oper Alert
template network.nexus.portchannel.bad {
subject = {{.Last.Status}}: {{.Eval .Alert.Vars.upDownByHost | printf "%.f" }} down Port-Channels on {{.Group.host}}
body = `{{ template "header" . }}
{{/* source is http://www.net-snmp.org/docs/mibs/interfaces.html . Oper and Admin are actually different in that Admin only includes up/down/testing. However, 1, 2, 3 of Oper status is the same as the first 3 of admin status, so the same map can be used */}}
{{ $statusReference := makeMap "1" "up" "2" "down" "3" "testing" "4" "unknown" "5" "dormat" "6" "not present" "7" "lowerLayerDown" }}
{{ $joinResult := .LeftJoin .Alert.Vars.adminUpAndOperDown .Alert.Vars.operStatus .Alert.Vars.adminStatus }}
{{ if notNil $joinResult }}
<h2>Port-Channels with Non-Healthy Status</h2>
<table>
<tr>
<th>Host</th>
<th>Desc</th>
<th>Operational Status</th>
<th>Administrative Status</th>
<tr>
{{ range $result := $joinResult }}
{{ $combinedStatus := index $result 0 }}
{{ $operStatus := index $result 1 }}
{{ $adminStatus := index $result 2 }}
{{ if (ne $combinedStatus.Value 0.0) and (eq $combinedStatus.Group.Host $.Group.Host) }}
<tr>
<!-- Show the value of the host tag key -->
<td>{{$combinedStatus.Group.iname}}</td>
<td>{{ $.GetMeta "" "alias" $combinedStatus.Group }}</td>
<td>
{{ $operValueString := $operStatus.Value | printf "%.f" }}
{{ index $statusReference $operValueString }} ({{ $operValueString }})
</td>
<td>
{{ $adminValueString := $adminStatus.Value | printf "%.f" }}
{{ index $statusReference $adminValueString }} ({{ $adminValueString }})
</td>
</tr>
{{ end }}
{{ end }}
<table>
{{ else }}
{{ .LastError }}
{{ end }}
<h2>Notes on Operational and Administrative Status<h2>
<h3>Operational Status</h3>
<p>The current operational state of the interface. The testing(3) state indicates that no operational packets can be passed. If ifAdminStatus is down(2) then ifOperStatus should be down(2). If ifAdminStatus is changed to up(1) then ifOperStatus should change to up(1) if the interface is ready to transmit and receive network traffic; it should change to dormant(5) if the interface is waiting for external actions (such as a serial line waiting for an incoming connection); it should remain in the down(2) state if and only if there is a fault that prevents it from going to the up(1) state; it should remain in the notPresent(6) state if the interface has missing (typically, hardware) components.</p>
<h3>Admininistrative Status</h3>
<p>The desired state of the interface. The testing(3) state indicates that no operational packets can be passed. When a managed system initializes, all interfaces start with ifAdminStatus in the down(2) state. As a result of either explicit management action or per configuration information retained by the managed system, ifAdminStatus is then changed to either the up(1) or testing(3) states (or remains in the down(2) state).</p>
`
}
alert network.nexus.portchannel.bad {
template = network.nexus.portchannel.bad
$notes = This will alert on a ny-nexus01 or ny-nexus02 (as the host level) if it has one more port-channels that have an administrative status of up but a operational status of down
$devices = ny-nexus01|ny-nexus02
$operStatus = last(q("sum:os.net.bond.oper_status{host=$devices,iname=wildcard(*)}", "1h", ""))
$adminStatus = last(q("sum:os.net.bond.admin_status{host=$devices,iname=wildcard(*)}", "1h", ""))
$adminUpAndOperDown = $adminStatus== 1 && $operStatus != 1
# Group interfaces by host since there would be too many alerts per port channel
$upDownByHost = sum(t($adminUpAndOperDown, "host"))
warn = $upDownByHost
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment