Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
print("Documentation of functions available for use in match expressions:")
longest = 0
for (funcname, description) in GraphNodeExpression.FunctionDescriptions():
if len(funcname) > longest:
longest = len(funcname)
fmt = "%%%ds: %%s" % longest
pad = (longest + 2) * " "
fmt2 = pad + "%s"
for (funcname, description) in GraphNodeExpression.FunctionDescriptions():
descriptions = description.split("\n")
print(fmt % (funcname, descriptions[0]))
for descr in descriptions[1:]:
print(fmt2 % descr)
MonitoringRule.load_tree("monrules")
def construct_from_file_name(filename):
"""
Construct a MonitoringRule from a filename parameter.
It will construct the appropriate subclass depending on its input
string. Note that the input is JSON -- with # comments.
"""
f = open(filename, "r")
s = f.read()
f.close()
return MonitoringRule.construct_from_string(s)
def monobjclass(mtype="service"):
"""Return the monitoring objects that go with this service type"""
return MonitoringRule.monitor_objects[mtype]
"/",
roles=(CMAconsts.ROLE_server,),
)
tests = [
(
oracleocfrule.specmatch(ExpressionContext((oraclenode, fdrone))),
MonitoringRule.HIGHPRIOMATCH,
),
(lsbsshrule.specmatch(ExpressionContext((sshnode, fdrone))), MonitoringRule.LOWPRIOMATCH),
(lsbsshrule.specmatch(ExpressionContext((udevnode, fdrone))), MonitoringRule.NOMATCH),
(lsbsshrule.specmatch(ExpressionContext((neonode, fdrone))), MonitoringRule.NOMATCH),
(neorule.specmatch(ExpressionContext((sshnode, fdrone))), MonitoringRule.NOMATCH),
(neorule.specmatch(ExpressionContext((neonode, fdrone))), MonitoringRule.LOWPRIOMATCH),
(neoocfrule.specmatch(ExpressionContext((neonode, fdrone))), MonitoringRule.HIGHPRIOMATCH),
(neoocfrule.specmatch(ExpressionContext((neonode, fdrone))), MonitoringRule.HIGHPRIOMATCH),
(
nagiossshrule.specmatch(ExpressionContext((sshnode, fdrone))),
MonitoringRule.MEDPRIOMATCH,
),
(nagiossshrule.specmatch(ExpressionContext((udevnode, fdrone))), MonitoringRule.NOMATCH),
(nagiossshrule.specmatch(ExpressionContext((neonode, fdrone))), MonitoringRule.NOMATCH),
(
nagiossensorsrule.specmatch(ExpressionContext((withsensors, fdrone))),
MonitoringRule.MEDPRIOMATCH,
),
(
nagiossensorsrule.specmatch(ExpressionContext((nosensors, fdrone))),
MonitoringRule.NOMATCH,
),
]
fieldmap = {"monitortype": str, "arglist": dict, "monitorclass": str, "provider": str}
assert testresult[1] is None
else:
assert isinstance(testresult[1], dict)
for field in fieldmap.keys():
assert field in testresult[1]
fieldvalue = testresult[1][field]
assert fieldvalue is None or isinstance(fieldvalue, fieldmap[field])
assert testresult[1]["monitorclass"] in ("ocf", "lsb", "nagios")
if testresult[1]["monitorclass"] == "ocf":
assert testresult[1]["provider"] is not None
assert isinstance(testresult[1]["arglist"], dict)
elif testresult[1]["monitorclass"] == "lsb":
assert testresult[1]["provider"] is None
assert testresult[1]["arglist"] is None
assert isinstance(testresult[1]["rscname"], str)
if testresult[0] == MonitoringRule.PARTMATCH:
assert testresult[1]["monitorclass"] in ("ocf",)
assert len(testresult) == 3
assert isinstance(testresult[2], (list, tuple)) # List of missing fields...
assert len(testresult[2]) > 0
print("Test %s passes [%s]." % (count, testresult))
print("Documentation of functions available for use in match expressions:")
longest = 0
for (funcname, description) in GraphNodeExpression.FunctionDescriptions():
if len(funcname) > longest:
longest = len(funcname)
fmt = "%%%ds: %%s" % longest
pad = (longest + 2) * " "
fmt2 = pad + "%s"
def constructaction(self, context):
"""Construct arguments
"""
return (
MonitoringRule.NEVERMATCH,
{
"monitorclass": "NEVERMON",
"monitortype": self.servicename,
"provider": None,
"arglist": None,
},
)
class OCFMonitoringRule(MonitoringRule):
"""Class for implementing monitoring rules for OCF style init script monitoring
OCF == Open Cluster Framework
"""
def __init__(self, provider, rsctype, triplespec):
"""
Parameters
----------
provider: str
The OCF provider name for this resource
This is the directory name this resource is found in
rsctype: str
The OCF resource type for this resource (service)
This is the same as the script name for the resource
triplespec: list
Return: None
"""
tree = os.walk(rootdirname, topdown=True, onerror=None, followlinks=followlinks)
pat = re.compile(pattern)
for walktuple in tree:
(dirpath, dirnames, filenames) = walktuple
dirnames.sort()
filenames.sort()
for filename in filenames:
if not pat.match(filename):
continue
path = os.path.join(dirpath, filename)
MonitoringRule.construct_from_file_name(path)
class LSBMonitoringRule(MonitoringRule):
"""Class for implementing monitoring rules for sucky LSB style init script monitoring
"""
def __init__(self, servicename, tuplespec):
self.servicename = servicename
MonitoringRule.__init__(self, "lsb", tuplespec)
def constructaction(self, context):
"""Construct arguments
"""
agentcache = MonitoringRule.compute_available_agents(context)
if "lsb" not in agentcache or self.servicename not in agentcache["lsb"]:
return (MonitoringRule.NOMATCH, None)
return (
MonitoringRule.LOWPRIOMATCH,
def __init__(self, servicename, tuplespec):
self.servicename = servicename
MonitoringRule.__init__(self, "lsb", tuplespec)
(
oracleocfrule.specmatch(ExpressionContext((oraclenode, fdrone))),
MonitoringRule.HIGHPRIOMATCH,
),
(lsbsshrule.specmatch(ExpressionContext((sshnode, fdrone))), MonitoringRule.LOWPRIOMATCH),
(lsbsshrule.specmatch(ExpressionContext((udevnode, fdrone))), MonitoringRule.NOMATCH),
(lsbsshrule.specmatch(ExpressionContext((neonode, fdrone))), MonitoringRule.NOMATCH),
(neorule.specmatch(ExpressionContext((sshnode, fdrone))), MonitoringRule.NOMATCH),
(neorule.specmatch(ExpressionContext((neonode, fdrone))), MonitoringRule.LOWPRIOMATCH),
(neoocfrule.specmatch(ExpressionContext((neonode, fdrone))), MonitoringRule.HIGHPRIOMATCH),
(neoocfrule.specmatch(ExpressionContext((neonode, fdrone))), MonitoringRule.HIGHPRIOMATCH),
(
nagiossshrule.specmatch(ExpressionContext((sshnode, fdrone))),
MonitoringRule.MEDPRIOMATCH,
),
(nagiossshrule.specmatch(ExpressionContext((udevnode, fdrone))), MonitoringRule.NOMATCH),
(nagiossshrule.specmatch(ExpressionContext((neonode, fdrone))), MonitoringRule.NOMATCH),
(
nagiossensorsrule.specmatch(ExpressionContext((withsensors, fdrone))),
MonitoringRule.MEDPRIOMATCH,
),
(
nagiossensorsrule.specmatch(ExpressionContext((nosensors, fdrone))),
MonitoringRule.NOMATCH,
),
]
fieldmap = {"monitortype": str, "arglist": dict, "monitorclass": str, "provider": str}
for count in range(0, len(tests)):
testresult = tests[count][0]
expected = tests[count][1]
assert testresult[0] == expected
if testresult[0] == MonitoringRule.NOMATCH:
def constructaction(self, context):
"""Construct arguments
"""
agentcache = MonitoringRule.compute_available_agents(context)
if "lsb" not in agentcache or self.servicename not in agentcache["lsb"]:
return (MonitoringRule.NOMATCH, None)
return (
MonitoringRule.LOWPRIOMATCH,
{
"monitorclass": "lsb",
"monitortype": self.servicename,
"rscname": "lsb_" + self.servicename, # There can only be one
"provider": None,
"arglist": None,
},