<commit_before>from octopy import *

def LinkModule():
	return {
	"var" : {
		"duplex_match" : LinkedVarArgMatch("duplex"),
		"speed_match" : LinkedVarArgMatch("speed"),
	},

	"react" : {
		Equals("duplex_match", False) :
			( Danger("tag", "ETH").Msg("loc", "{source.in_n:ip}")
				.Msg("descr", "mismatch duplex mode on two sides of the link")
				.Msg("msg"  , "mismatch duplex mode on two sides of the link from {target:ip} to {source:ip}")
			, Recover("tag", "ETH").Msg("loc", "{source.in_n:ip}")
				.Msg("descr", "duplex on the link is ok")
				.Msg("msg"  , "duplex on the link is ok from {target:ip} to {source:ip}")),

		Equals("speed_match", False) :
			( Danger("tag", "ETH").Msg("loc", "{source.in_n:ip}")
				.Msg("descr", "mismatch speed on two sides of the link")
				.Msg("msg"  , "mismatch speed on two sides of the link  from {target:ip} to {source:ip}")
			, Recover("tag", "ETH").Msg("loc", "{source.in_n:ip}")
				.Msg("descr", "speed on the link is ok")
				.Msg("msg"  , "speed on the link is ok from {target:ip} to {source:ip}")),
	}
}

def PortModule(timeout = UPDATE_TIME_NOT_SPECIFIED, loc = None, loc_s = None, loc_l = None):
	"""requires user to define 'speed_req'"""

	if loc is None:
		loc = "{in_n:ip}"

	if loc_s is None:
		loc_s = "{in_n:type} {type}: "

	if loc_l is None:
		loc_l = "{in_n:type}[{in_n:ip}] {type}[{id}]: "

	return {
		"sensor" : {
			"admin_status" : String(UPDATE_TIME_NOT_SPECIFIED, "up"),
			"duplex_req" : String(UPDATE_TIME_NOT_SPECIFIED, "full"),
			"oper_status" : String(timeout),
			"duplex" : String(timeout),
			"speed" : Long(timeout),
		},

		"var" : {
			"status_match" : ArgMatch("oper_status", "admin_status"),
			"duplex_match" : ArgMatch("duplex", "duplex_req"),
			"speed_match" : ArgMatch("speed", "speed_req"),
		},

		"react" : {
			Equals("status_match", False) :
				( Danger("tag", "ETH").Msg("loc", loc)
					.Msg("descr", loc_s + "is down")
					.Msg("msg"  , loc_l + "is down")
				, Recover("tag", "ETH").Msg("loc", loc)
					.Msg("descr", loc_s + "is up")
					.Msg("msg"  , loc_l + "is up")),

			Equals("duplex_match", False) :
				( Danger("tag", "ETH").Msg("loc", loc)
					.Msg("descr", loc_s + "wrong duplex mode")
					.Msg("msg"  , loc_l + "wrong duplex mode({duplex})")
				, Recover("tag", "ETH").Msg("loc", loc)<commit_msg>add optional name and descr for port<commit_after>from octopy import *

def LinkModule():
	return {
	"var" : {
		"duplex_match" : LinkedVarArgMatch("duplex"),
		"speed_match" : LinkedVarArgMatch("speed"),
	},

	"react" : {
		Equals("duplex_match", False) :
			( Danger("tag", "ETH").Msg("loc", "{source.in_n:ip}")
				.Msg("descr", "mismatch duplex mode on two sides of the link")
				.Msg("msg"  , "mismatch duplex mode on two sides of the link from {target:ip} to {source:ip}")
			, Recover("tag", "ETH").Msg("loc", "{source.in_n:ip}")
				.Msg("descr", "duplex on the link is ok")
				.Msg("msg"  , "duplex on the link is ok from {target:ip} to {source:ip}")),

		Equals("speed_match", False) :
			( Danger("tag", "ETH").Msg("loc", "{source.in_n:ip}")
				.Msg("descr", "mismatch speed on two sides of the link")
				.Msg("msg"  , "mismatch speed on two sides of the link  from {target:ip} to {source:ip}")
			, Recover("tag", "ETH").Msg("loc", "{source.in_n:ip}")
				.Msg("descr", "speed on the link is ok")
				.Msg("msg"  , "speed on the link is ok from {target:ip} to {source:ip}")),
	}
}

def PortModule(timeout = UPDATE_TIME_NOT_SPECIFIED, loc = None, loc_s = None, loc_l = None):
	"""requires user to define 'speed_req'"""

	if loc is None:
		loc = "{in_n:ip}"

	if loc_s is None:
		loc_s = "{in_n:type} {type}: "

	if loc_l is None:
		loc_l = "{in_n:type}[{in_n:ip}] {type}[{id}][{name}][{descr}]: "

	return {
		"sensor" : {
			"name" : String(UPDATE_TIME_NOT_SPECIFIED, ""),
			"descr" : String(UPDATE_TIME_NOT_SPECIFIED, ""),

			"admin_status" : String(UPDATE_TIME_NOT_SPECIFIED, "up"),
			"duplex_req" : String(UPDATE_TIME_NOT_SPECIFIED, "full"),
			"oper_status" : String(timeout),
			"duplex" : String(timeout),
			"speed" : Long(timeout),
		},

		"var" : {
			"status_match" : ArgMatch("oper_status", "admin_status"),
			"duplex_match" : ArgMatch("duplex", "duplex_req"),
			"speed_match" : ArgMatch("speed", "speed_req"),
		},

		"react" : {
			Equals("status_match", False) :
				( Danger("tag", "ETH").Msg("loc", loc)
					.Msg("descr", loc_s + "is down")
					.Msg("msg"  , loc_l + "is down")
				, Recover("tag", "ETH").Msg("loc", loc)
					.Msg("descr", loc_s + "is up")
					.Msg("msg"  , loc_l + "is up")),

			Equals("duplex_match", False) :
				( Danger("tag", "ETH").Msg("loc", loc)
					.Msg("descr", loc_s + "wrong duplex mode")
					.Msg("msg"  , loc_l + "wrong duplex mode({duplex})")
				, Recover("tag", "ETH").Msg("loc", loc)
{'fraction_non_alphanumeric': 0.2095357590966123, 'fraction_numerical': 0.0, 'mean_word_length': 3.961618257261411, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7019424', 'n_tokens_mistral': 2087, 'n_tokens_neox': 1844, 'n_words': 431}