/*
	This file contains some sample policy-statements.

	Note to VIM users: this file should have syntax highlighting; enable with (:syntax on).
*/

#include "@resolved_sysconfdir@/format-statements.conf"
#include "@resolved_sysconfdir@/map-statements.conf"

policy-options {
	/*
		Policy that handles RFC1850 OSPF Traps.
	*/
	policy-statement OSPF_TRAP {
		term OSPF_INTERFACE_STATE_CHANGE {
			from {
				protocol snmptrap;
				event		snmp:ospfIfStateChange;
			}
			then {
				apply-map SOURCE_TO_ELEMENT_DATA_MAP;
				set {
					state information;
				}
				output {
					gui {
						brief		"OSPF interface state now @snmp:ospfIfState@";
						detail	"The OSPF interface state on @snmp:ifDescr@ changed to @snmp:ospfIfState@";
						channel 	routing-ospf;
					}
					syslog {
						detail	"@snmp:sysName.0@: OSPF state on @snmp:ifDescr@ changed to @snmp:ospfIfState@";
						channel 	routing-ospf;
					}
				}
				accept;
			}
		}
		term OSPF_VIRTUAL_INTERFACE_STATE_CHANGE {
			from {
				protocol snmptrap;
				event		snmp:ospfVirtIfStateChange;
			}
			then {
				apply-map SOURCE_TO_ELEMENT_DATA_MAP;
				set {
					state information;
				}
				output {
					gui {
						detail	"OSPF virtual interface state now @snmp:ospfIfState@";
						detail	"The OSPF virtual interface state to @snmp:ospfVirtIfNeighbor@ over area @snmp:ospfVirtIfAreaId@ changed to @snmp:ospfIfState@";
						channel 	routing-ospf;
					}
					syslog {
						detail	"@snmp:sysName.0@: OSPF state to @snmp:ospfVirtIfNeighbor@ over area @snmp:ospfVirtIfAreaId@ changed to @snmp:ospfIfState@";
						channel 	routing-ospf;
					}
				}
				accept;
			}
		}
		term OSPF_NEIGHBOR_STATE_CHANGE {
			from {
				protocol	snmptrap;
				event		snmp:ospfNbrStateChange;
			}
			then {
				apply-map SOURCE_TO_ELEMENT_DATA_MAP;
				set {
					state information;
				}
				evaluate {
					policy-statement LOOKUP_OSPF_NEIGHBOR_DATA {
						foo.bar	"FIXME: Needs variable to function.";
					}
				}
				output {
					gui {
						brief		"OSPF neighbor @snmp:ospfNbrRtrId@ (@neighbor-element@) state now @snmp:ospfNbrState@";
						detail	"The OSPF neighbor @snmp:ospfNbrRtrId@ (@neighbor-element@) state changed to @snmp:ospfNbrState@";
						channel 	routing-ospf;
					}
					syslog {
						detail	"@snmp:sysName.0@: OSPF neighbor @snmp:ospfNbrRtrId@ (@neighbor-element@) changed state to @snmp:ospfNbrState@";
						channel 	routing-ospf;
					}
				}
				accept;
			}
		}
		term OSPF_VIRTUAL_NEIGHBOR_STATE_CHANGE {
			from {
				protocol	snmptrap;
				event		snmp:ospfVirtNbrStateChange;
			}
			then {
				apply-map SOURCE_TO_ELEMENT_DATA_MAP;
				set {
					state information;
				}
				output {
					gui {
						brief		"OSPF virtual neighbor @snmp:ospfVirtNbrRtrId@ state now @snmp:ospfNbrState@";
						detail	"The OSPF virtual neighbor @snmp:ospfVirtNbrRtrId@ over area @snmp:ospfVirtNbrArea@ changed state to @snmp:ospfNbrState@";
						channel 	routing-ospf;
					}
					syslog {
						detail	"@snmp:sysName.0@: OSPF virtual neighbor @snmp:ospfVirtNbrRtrId@ over area @snmp:ospfVirtNbrArea@ changed state to @snmp:ospfNbrState@";
						channel 	routing-ospf;
					}
				}
				accept;
			}
		}
		term OSPF_INTERFACE_CONFIG_ERROR {
			from {
				protocol	snmptrap;
				event		snmp:ospfIfConfigError;
			}
			then {
				apply-map SOURCE_TO_ELEMENT_DATA_MAP;
				set {
					state information;
				}
				output {
					gui {
						brief		"OSPF adjacency failed with @snmp:ospfPacketSrc@ due to @snmp:ospfConfigErrorType@";
						detail	"Failed to form an OSPF adjacency with @snmp:ospfPacketSrc@ due to @snmp:ospfConfigErrorType@.";
						channel 	routing-ospf;
					}
					syslog {
						detail	"@snmp:sysName.0@: failed to form an OSPF adjacency with @snmp:ospfPacketSrc@ due to @snmp:ospfConfigErrorType@";
						channel 	routing-ospf;
					}
				}
				accept;
			}
		}
		term OSPF_VIRTUAL_INTERFACE_CONFIG_ERROR {
			from {
				protocol	snmptrap;
				event		snmp:ospfVirtIfConfigError;
			}
			then {
				apply-map SOURCE_TO_ELEMENT_DATA_MAP;
				set {
					state information;
				}
				output {
					gui {
						brief		"OSPF virtual adjacency failed with @snmp:ospfVirtIfNeighbor@ due to @snmp:ospfConfigErrorType@";
						detail	"Failed to form an OSPF virtual adjacency with @snmp:ospfVirtIfNeighbor@ due to @snmp:ospfConfigErrorType@.";
						channel 	routing-ospf;
					}
					syslog {
						detail	"@snmp:sysName.0@: failed to form an OSPF virtual adjacency with @snmp:ospfPacketSrc@ due to @snmp:ospfConfigErrorType@";
						channel 	routing-ospf;
					}
				}
				accept;
			}
		}
		term OSPF_INTERFACE_AUTHENTICATION_FAILURE {
			from {
				protocol	snmptrap;
				event		snmp:ospfIfAuthFailure;
			}
			then {
				apply-map SOURCE_TO_ELEMENT_DATA_MAP;
				set {
					state information;
				}
				output {
					gui {
						brief		"Invalid OSPF auth key from @snmp:ospfPacketSrc@";
						detail	"An invalid OSPF authentication key (@snmp:ospfConfigErrorType@) was recieved from neighbor @snmp:ospfPacketSrc@ on interface @snmp:ifDescr@.";
						channel 	routing-ospf;
					}
					syslog {
						detail	"@snmp:sysName.0@: recieved an invalid OSPF authentication key (@snmp:ospfConfigErrorType@) from neighbor @snmp:ospfPacketSrc@ on interface @snmp:ifDescr@";
						channel 	routing-ospf;
					}
				}
				accept;
			}
		}
		term OSPF_VIRTUAL_INTERFACE_AUTHENTICATION_FAILURE {
			from {
				protocol	snmptrap;
				event		snmp:ospfVirtIfAuthFailure;
			}
			then {
				apply-map SOURCE_TO_ELEMENT_DATA_MAP;
				set {
					state information;
				}
				output {
					gui {
						brief		"Invaid OSPF auth key (virtual) from @snmp:ospfVirtIfNeighbor@";
						detail	"An invalid OSPF authentication key (@snmp:ospfConfigErrorType@) was recieved from virtual neighbor @snmp:ospfVirtIfNeighbor@.";
						channel 	routing-ospf;
					}
					syslog {
						detail	"@snmp:sysName.0@: recieved an invalid OSPF authentication key (@snmp:ospfConfigErrorType@) from virtual neighbor @snmp:ospfVirtIfNeighbor@";
						channel 	routing-ospf;
					}
				}
				accept;
			}
		}
		term OSPF_INTERFACE_RECIEVED_BAD_PACKET {
			from {
				protocol	snmptrap;
				event		snmp:ospfIfRxBadPacket;
			}
			then {
				apply-map SOURCE_TO_ELEMENT_DATA_MAP;
				set {
					state information;
				}
				output {
					gui {
						brief		"Corrupt @snmp:ospfPacketType@ OSPF packet from @snmp:ospfPacketSrc@";
						detail	"Recieved corrupt @snmp:ospfPacketType@ OSPF packet from neighbor @snmp:ospfPacketSrc@ on interface @snmp:ifDescr@";
						channel 	routing-ospf;
					}
					syslog {
						detail	"@snmp:sysName.0@: recieved a corrupt @snmp:ospfPacketType@ OSPF packet from neighbor @snmp:ospfPacketSrc@ on interface @snmp:ifDescr@";
						channel 	routing-ospf;
					}
				}
				accept;
			}
		}
		term OSPF_VIRTUAL_INTERFACE_RECIEVED_BAD_PACKET {
			from {
				protocol	snmptrap;
				event		snmp:ospfVirtIfRxBadPacket;
			}
			then {
				apply-map SOURCE_TO_ELEMENT_DATA_MAP;
				set {
					state information;
				}
				output {
					gui {
						brief		"Corrupt @snmp:ospfPacketType@ OSPF packet from @snmp:ospfVirtIfNeighbor@ (virtual)";
						detail	"Recieved corrupt @snmp:ospfPacketType@ OSPF packet from virtual neighbor @snmp:ospfVirtIfNeighbor@.";
						channel 	routing-ospf;
					}
					syslog {
						detail	"@snmp:sysName.0@: recieved a corrupt @snmp:ospfPacketType@ OSPF packet from virtual neighbor @snmp:ospfVirtIfNeighbor@";
						channel 	routing-ospf;
					}
				}
				accept;
			}
		}
		term OSPF_INTERFACE_RETRANSMISSION {
			from {
				protocol	snmptrap;
				event		snmp:ospfTxRetransmit;
			}
			then {
				apply-map SOURCE_TO_ELEMENT_DATA_MAP;
				set {
					state information;
				}
				output {
					syslog {
						detail	"@snmp:sysName.0@: retransmitted @snmp:ospfPacketType@ OSPF packet to neighbor @snmp:ospfNbrRtrId@ on interface @snmp:ifDescr@";
						channel 	routing-ospf;
					}
				}
				accept;
			}
		}
		term OSPF_VIRTUAL_INTERFACE_RETRANSMISSION {
			from {
				protocol	snmptrap;
				event		snmp:ospfVirtIfTxRetransmit;
			}
			then {
				apply-map SOURCE_TO_ELEMENT_DATA_MAP;
				set {
					state information;
				}
				output {
					syslog {
						detail	"@snmp:sysName.0@: retransmitted @snmp:ospfPacketType@ OSPF packet to virtual neighbor @snmp:ospfVirtIfNeighbor@";
						channel 	routing-ospf;
					}
				}
				accept;
			}
		}
		term OSPF_LSDB_OVERFLOW {
			from {
				protocol	snmptrap;
				event		snmp:ospfLsdbOverflow;
			}
			then {
				apply-map SOURCE_TO_ELEMENT_DATA_MAP;
				set {
					state information;
				}
				output {
					gui {
						brief		"OSPF LSDB overflow";
						detail	"The OSPF link state database has reached the overflow limit of @snmp:ospfExtLsdbLimit@ LSAs. This can occur when an excessive amount of routes have been readvertised into OSPF.";
						channel 	routing-ospf;
					}
					syslog {
						detail	"@snmp:sysName.0@: OSPF LSDB on @snmp:sysName.0@ (@source@) has reached the overflow limit of @snmp:ospfExtLsdbLimit@ LSAs";
						channel 	routing-ospf;
					}
				}
				accept;
			}
		}
		term OSPF_LSDB_APPROACHING_OVERFLOW {
			from {
				protocol	snmptrap;
				event		snmp:ospfLsdbApproachingOverflow;
			}
			then {
				apply-map SOURCE_TO_ELEMENT_DATA_MAP;
				set {
					state information;
				}
				output {
					gui {
						brief		"OSPF LSDB approaching overflow";
						detail	"The OSPF link state database has reached 90% of the overflow limit of @snmp:ospfExtLsdbLimit@ LSAs. This can occur when an excessive amount of routes have been readvertised into OSPF.";
						channel 	routing-ospf;
					}
					syslog {
						detail	"@snmp:sysName.0@: OSPF LSDB on @snmp:sysName.0@ (@source@) has reached 90% of the overflow limit of @snmp:ospfExtLsdbLimit@ LSAs";
						channel 	routing-ospf;
					}
				}
				accept;
			}
		}
		apply-format SNMPTRAP_FORMAT;
	}

	policy-statement LOOKUP_OSPF_NEIGHBOR_DATA {
		term NEIGHBOR_ELEMENT_DATA {
			from {
				protocol	snmptrap;
				event		snmp:ospfNbrStateChange;
			}
			then {
				apply-map NEIGHBOR_TO_NEIGHBOR_ELEMENT_MAP;
				accept;
			}
		}
		apply-format SNMPTRAP_FORMAT;
	}

	map-statement NEIGHBOR_TO_NEIGHBOR_ELEMENT_MAP {
		term GET_NEIGHBOR_ELEMENT_ID {
			from {
				defined snmp:ospfNbrRtrId;
				defined-except neighbor-element-id;
				query "SELECT element.id AS neighbor_element_id FROM element, interface, ip, ip_data WHERE element.id = interface.element AND interface.id = ip.interface AND ip_data.ip = ip.id AND ip_data.value = '@snmp:ospfNbrRtrId@' LIMIT 1";
			}
			then {
				set {
					neighbor-element-id	@neighbor_element_id@;
				}
			}
		}
		term GET_NEIGHBOR_ELEMENT {
			from {
				defined neighbor-element-id;
				query "SELECT value AS neighbor_element FROM element_data WHERE element_data.variable = 'snmp:sysName.0' AND element_data.element = '@neighbor-element-id@'";
			}
			then {
				set {
					neighbor-element @neighbor_element@;
				}
			}
		}
	}
}

/*
** Local Variables:
** c-basic-offset: 3
** tab-width: 3
** End:
** vim600: fdm=marker
** vim: noet ts=3 sw=3
** vim: syntax=sella_nms
*/
