/*
	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-statement BGP_TRAP {
		term BGP_SESSION_DOWN {
			from {
				protocol	snmptrap;
				event		snmp:bgpBackwardTransition;
			}
			then {
				apply-map	BGP_PEER_REMOTE_ADDR_TO_ASN_DATA_MAP;
				set {
					state		information;
				}
				evaluate {
					policy-statement TRANSLATE_BGP_ERROR {
						foo.bar	"FIXME: sub policies need a variable";
					}
				}
				output {
					gui {
						brief		"BGP session down for @peer-name@ ASN @peer-asn@ (@snmp:bgpPeerRemoteAddr@)";
						detail	"BGP session is down for @peer-name@ ASN @peer-asn@ (@snmp:bgpPeerRemoteAddr@) due to @snmp:bgpPeerLastError@. Email: @peer-email@ Phone: @peer-phone@";
						channel	routing-bgp;
					}
					syslog {
						detail	"@snmp:sysName.0@: peering session down for @peer-name@ ASN @peer-asn@ (@snmp:bgpPeerRemoteAddr@) due to @snmp:bgpPeerLastError@";
						channel	routing-bgp;
					}
				}
				accept;
			}
		}
		term BGP_SESSION_UP {
			from {
				protocol snmptrap;
				event		snmp:bgpEstablished;
			}
			then {
				apply-map	BGP_PEER_REMOTE_ADDR_TO_ASN_DATA_MAP;
				set {
					state		information;
				}
				evaluate {
					policy-statement TRANSLATE_BGP_ERROR {
						foo.bar	"FIXME: sub policies need a variable";
					}
				}
				output {
					gui {
						brief		"BGP session established for @peer-name@ ASN @peer-asn@ (@snmp:bgpPeerRemoteAddr@)";
						detail	"BGP session established for @peer-name@ ASN @peer-asn@ (@snmp:bgpPeerRemoteAddr@). Last BGP error was: @snmp:bgpPeerLastError@. Email: @peer-email@ Phone: @peer-phone@";
						channel	routing-bgp;
					}
					syslog {
						detail	"@snmp:sysName.0@: peering session established for @peer-name@ ASN @peer-asn@ (@snmp:bgpPeerRemoteAddr@). Last BGP error was: @snmp:bgpPeerLastError@ ";
						channel	routing-bgp;
					}
				}
				accept;
			}
		}
		apply-format SNMPTRAP_FORMAT;
	}

	policy-statement TRANSLATE_BGP_ERROR {
		term UNSPECIFIED {
			from snmp:bgpPeerLastError "00 00";
			then {
				set snmp:bgpPeerLastError "an unspecified error";
				accept;
			}
		}
		term CONNECTION_NOT_SYNCRONIZED {
			from snmp:bgpPeerLastError "01 01";
			then {
				set snmp:bgpPeerLastError "the connection is not synchronized";
				accept;
			}
		}
		term BAD_MESSAGE_LENGTH {
			from snmp:bgpPeerLastError "01 02";
			then {
				set snmp:bgpPeerLastError "a bad BGP message length";
				accept;
			}
		}
		term BAD_MESSAGE_TYPE {
			from snmp:bgpPeerLastError "01 03";
			then {
				set snmp:bgpPeerLastError "a bad BGP message type";
				accept;
			}
		}
		term UNSUPPORTED_VERSION {
			from snmp:bgpPeerLastError "02 01";
			then {
				set snmp:bgpPeerLastError "an unsupported BGP version number";
				accept;
			}
		}
		term PEER_ASN_MISMATCH {
			from snmp:bgpPeerLastError "02 02";
			then {
				set snmp:bgpPeerLastError "a peer ASN mismatch";
				accept;
			}
		}
		term PEER_IDENTIFIER_MISMATCH {
			from snmp:bgpPeerLastError "02 03";
			then {
				set snmp:bgpPeerLastError "a peer BGP identifier mismatch";
				accept;
			}
		}
		term UNSUPPORTED_PARAMETER {
			from snmp:bgpPeerLastError "02 04";
			then {
				set snmp:bgpPeerLastError "an unsupported optional parameter";
				accept;
			}
		}
		term AUTH_FAILURE {
			from snmp:bgpPeerLastError "02 05";
			then {
				set snmp:bgpPeerLastError "an authentication failure";
				accept;
			}
		}
		term UNACCEPTABLE_HOLD_TIME {
			from snmp:bgpPeerLastError "02 06";
			then {
				set snmp:bgpPeerLastError "an unacceptable hold time";
				accept;
			}
		}
		term MALFORMED_ATTRIBUTE {
			from snmp:bgpPeerLastError "03 01";
			then {
				set snmp:bgpPeerLastError "a malformed attribute list";
				accept;
			}
		}	
		term UNRECOGNIZED_ATTRIBUTE {
			from snmp:bgpPeerLastError "03 02";
			then {
				set snmp:bgpPeerLastError "an unrecogized well known attribute";
				accept;
			}
		}	
		term MISSING_ATTRIBUTE {
			from snmp:bgpPeerLastError "03 03";
			then {
				set snmp:bgpPeerLastError "a missing well known attribute";
				accept;
			}
		}	
		term ATTRIBUTE_FLAG_ERROR {
			from snmp:bgpPeerLastError "03 04";
			then {
				set snmp:bgpPeerLastError "an attribute flag error";
				accept;
			}
		}	
		term ATTRIBUTE_LENGTH_ERROR {
			from snmp:bgpPeerLastError "03 05";
			then {
				set snmp:bgpPeerLastError "an attribute length error";
				accept;
			}
		}	
		term INVALID_ORIGIN {
			from snmp:bgpPeerLastError "03 06";
			then {
				set snmp:bgpPeerLastError "an invalid origin";
				accept;
			}
		}	
		term AS_ROUTING_LOOP {
			from snmp:bgpPeerLastError "03 07";
			then {
				set snmp:bgpPeerLastError "an AS routing loop";
				accept;
			}
		}	
		term INVALID_NEXT_HOP {
			from snmp:bgpPeerLastError "03 08";
			then {
				set snmp:bgpPeerLastError "an invalid next-hop";
				accept;
			}
		}	
		term OPTIONAL_ATTRIBUTE_ERROR {
			from snmp:bgpPeerLastError "03 09";
			then {
				set snmp:bgpPeerLastError "an optional attribute error";
				accept;
			}
		}	
		term INVALID_NETWORK_FIELD {
			from snmp:bgpPeerLastError "03 0A";
			then {
				set snmp:bgpPeerLastError "an invalid network field";
				accept;
			}
		}	
		term MALFORMED_AS_PATH {
			from snmp:bgpPeerLastError "03 0B";
			then {
				set snmp:bgpPeerLastError "a malformed AS path";
				accept;
			}
		}	
		term HOLD_TIMER {
			from snmp:bgpPeerLastError "04 00";
			then {
				set snmp:bgpPeerLastError "a hold timer expiration";
				accept;
			}
		}	
		term STATE_MACHINE {
			from snmp:bgpPeerLastError "05 00";
			then {
				set snmp:bgpPeerLastError "a BGP finite state machine error";
				accept;
			}
		}	
		term CEASE {
			from	snmp:bgpPeerLastError "06 00";
			then {
				set snmp:bgpPeerLastError "a BGP cease message";
			}
		}
		term MAX_PREFIX {
			from	snmp:bgpPeerLastError "06 01";
			then {
				set snmp:bgpPeerLastError "a maximum prefix limit";
			}
		}
		term ADMIN_DOWN {
			from	snmp:bgpPeerLastError "06 02";
			then {
				set snmp:bgpPeerLastError "an administrative shutdown";
			}
		}
		term PEER_UNCONFIGURED {
			from	snmp:bgpPeerLastError "06 03";
			then {
				set snmp:bgpPeerLastError "peer was unconfigured";
			}
		}
		term ADMIN_RESET {
			from	snmp:bgpPeerLastError "06 04";
			then {
				set snmp:bgpPeerLastError "an administrative reset";
			}
		}
		term CONNECTION_REJECTION {
			from	snmp:bgpPeerLastError "06 05";
			then {
				set snmp:bgpPeerLastError "remote peer rejected connection";
			}
		}
		term CONFIG_CHANGE {
			from	snmp:bgpPeerLastError "06 06";
			then {
				set snmp:bgpPeerLastError "an interruptive configuration change";
			}
		}
		term CONNECTION_COLLISION {
			from	snmp:bgpPeerLastError "06 07";
			then {
				set snmp:bgpPeerLastError "a connection collision resolution";
			}
		}
		apply-format BGP_ERROR_TRANSLATION_FORMAT;
	}

	format-statement BGP_ERROR_TRANSLATION_FORMAT {
		term ERROR_CODES {
			from {
				variable snmp:bgpPeerLastError {
					required	yes;

					type		[ string regex ];
					function	equal-to;
				}
			}
		}
	}
}

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