add missing routeros tools from dinotools
This commit is contained in:
parent
e4b6fed5f2
commit
60c4f1870f
35 changed files with 5085 additions and 1 deletions
124
py/libs/check_routeros/routeros_check/check/interface_vrrp.py
Normal file
124
py/libs/check_routeros/routeros_check/check/interface_vrrp.py
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
# SPDX-FileCopyrightText: PhiBo DinoTools (2021)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import click
|
||||
import librouteros
|
||||
import librouteros.query
|
||||
import nagiosplugin
|
||||
|
||||
from ..cli import cli
|
||||
from ..context import BooleanContext
|
||||
from ..helper import logger
|
||||
from ..resource import RouterOSCheckResource
|
||||
|
||||
|
||||
class InterfaceVrrpCheck(RouterOSCheckResource):
|
||||
name = "VRRP"
|
||||
|
||||
def __init__(self, cmd_options, name, master_must):
|
||||
super().__init__(cmd_options=cmd_options)
|
||||
|
||||
self._name = name
|
||||
self.backup = None
|
||||
self.disabled = None
|
||||
self.enabled = None
|
||||
self.invalid = None
|
||||
self.master = None
|
||||
self.master_must = master_must
|
||||
self.running = None
|
||||
|
||||
def probe(self):
|
||||
key_name = librouteros.query.Key("name")
|
||||
api = self._connect_api()
|
||||
|
||||
logger.info("Fetching data ...")
|
||||
call = api.path(
|
||||
"/interface/vrrp"
|
||||
).select(
|
||||
key_name,
|
||||
librouteros.query.Key("backup"),
|
||||
librouteros.query.Key("disabled"),
|
||||
librouteros.query.Key("invalid"),
|
||||
librouteros.query.Key("master"),
|
||||
librouteros.query.Key("running"),
|
||||
).where(
|
||||
key_name == self._name
|
||||
)
|
||||
results = tuple(call)
|
||||
result = results[0]
|
||||
|
||||
self.disabled = result["disabled"]
|
||||
self.enabled = not self.disabled
|
||||
|
||||
yield nagiosplugin.Metric(
|
||||
name="disabled",
|
||||
value=self.disabled,
|
||||
)
|
||||
|
||||
if self.enabled:
|
||||
for n in ("backup", "invalid", "master", "running"):
|
||||
if n not in result:
|
||||
continue
|
||||
|
||||
setattr(self, n, result[n])
|
||||
yield nagiosplugin.Metric(
|
||||
name=n,
|
||||
value=result[n],
|
||||
)
|
||||
|
||||
|
||||
class InterfaceVrrpDisabled(BooleanContext):
|
||||
def evaluate(self, metric, resource: InterfaceVrrpCheck):
|
||||
if metric.value is True:
|
||||
return self.result_cls(nagiosplugin.state.Warn, "VRRP is disabled", metric)
|
||||
return self.result_cls(nagiosplugin.state.Ok)
|
||||
|
||||
|
||||
class InterfaceVrrpInvalid(BooleanContext):
|
||||
def evaluate(self, metric, resource: InterfaceVrrpCheck):
|
||||
if metric.value is True:
|
||||
return self.result_cls(
|
||||
state=nagiosplugin.state.Warn,
|
||||
hint="VRRP config is invalid"
|
||||
)
|
||||
return self.result_cls(nagiosplugin.state.Ok)
|
||||
|
||||
|
||||
class InterfaceVrrpMaster(BooleanContext):
|
||||
def evaluate(self, metric, resource: InterfaceVrrpCheck):
|
||||
if not metric.value and resource.master_must:
|
||||
return self.result_cls(
|
||||
state=nagiosplugin.state.Warn,
|
||||
hint="VRRP interface is not master"
|
||||
)
|
||||
return self.result_cls(nagiosplugin.state.Ok)
|
||||
|
||||
|
||||
@cli.command("interface.vrrp")
|
||||
@click.option(
|
||||
"--name",
|
||||
required=True,
|
||||
help="The name of the VRRP interface to check",
|
||||
)
|
||||
@click.option(
|
||||
"--master",
|
||||
default=False,
|
||||
help="If set the interface must be master",
|
||||
)
|
||||
@click.pass_context
|
||||
def interface_vrrp(ctx, name, master):
|
||||
"""Check the state of VRRP interfaces"""
|
||||
check = nagiosplugin.Check(
|
||||
InterfaceVrrpCheck(
|
||||
cmd_options=ctx.obj,
|
||||
name=name,
|
||||
master_must=master,
|
||||
),
|
||||
BooleanContext("backup"),
|
||||
InterfaceVrrpDisabled("disabled"),
|
||||
InterfaceVrrpInvalid("invalid"),
|
||||
InterfaceVrrpMaster("master"),
|
||||
BooleanContext("running")
|
||||
)
|
||||
|
||||
check.main(verbose=ctx.obj["verbose"])
|
||||
Loading…
Add table
Add a link
Reference in a new issue