From 605cac35526c8dfe409891f777d50547fb94392f Mon Sep 17 00:00:00 2001 From: Viacheslav Date: Wed, 29 Sep 2021 14:17:21 +0000 Subject: monitoring: T3872: Add a new feature service monitoring telegraf --- .../custom_scripts/show_interfaces_input_filter.py | 47 +++++++++++++++++ .../custom_scripts/vyos_services_input_filter.py | 61 ++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100755 src/etc/telegraf/custom_scripts/show_interfaces_input_filter.py create mode 100755 src/etc/telegraf/custom_scripts/vyos_services_input_filter.py (limited to 'src/etc/telegraf/custom_scripts') diff --git a/src/etc/telegraf/custom_scripts/show_interfaces_input_filter.py b/src/etc/telegraf/custom_scripts/show_interfaces_input_filter.py new file mode 100755 index 000000000..0f5e366cd --- /dev/null +++ b/src/etc/telegraf/custom_scripts/show_interfaces_input_filter.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +import subprocess +import time + +def status_to_int(status): + switcher={ + 'u':'0', + 'D':'1', + 'A':'2' + } + return switcher.get(status,"") + +def description_check(line): + desc=" ".join(line[3:]) + if desc == "": + return "empty" + else: + return desc + +def gen_ip_list(index,interfaces): + line=interfaces[index].split() + ip_list=line[1] + if index < len(interfaces): + index += 1 + while len(interfaces[index].split())==1: + ip = interfaces[index].split() + ip_list = ip_list + " " + ip[0] + index += 1 + if index == len(interfaces): + break + return ip_list + +interfaces = subprocess.check_output("/usr/libexec/vyos/op_mode/show_interfaces.py --action=show-brief", shell=True).decode('utf-8').splitlines() +del interfaces[:3] +lines_count=len(interfaces) +index=0 +while index1: + print(f'show_interfaces,interface={line[0]} ' + f'ip_addresses="{gen_ip_list(index,interfaces)}",' + f'state={status_to_int(line[2][0])}i,' + f'link={status_to_int(line[2][2])}i,' + f'description="{description_check(line)}" ' + f'{str(int(time.time()))}000000000') + index += 1 diff --git a/src/etc/telegraf/custom_scripts/vyos_services_input_filter.py b/src/etc/telegraf/custom_scripts/vyos_services_input_filter.py new file mode 100755 index 000000000..df4eed131 --- /dev/null +++ b/src/etc/telegraf/custom_scripts/vyos_services_input_filter.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2021 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +import time +from vyos.configquery import ConfigTreeQuery +from vyos.util import is_systemd_service_running, process_named_running + +# Availible services and prouceses +# 1 - service +# 2 - process +services = { + "protocols bgp" : "bgpd", + "protocols ospf" : "ospfd", + "protocols ospfv3" : "ospf6d", + "protocols rip" : "ripd", + "protocols ripng" : "ripngd", + "protocols isis" : "isisd", + "service pppoe" : "accel-ppp@pppoe.service", + "vpn l2tp remote-access" : "accel-ppp@l2tp.service", + "vpn pptp remote-access" : "accel-ppp@pptp.service", + "vpn sstp" : "accel-ppp@sstp.service", + "vpn ipsec" : "charon" +} + +# Configured services +conf_services = { + 'zebra' : 0, + 'staticd' : 0, +} +# Get configured service and create list to check if process running +config = ConfigTreeQuery() +for service in services: + if config.exists(service): + conf_services[services[service]] = 0 + +for conf_service in conf_services: + status = 0 + if ".service" in conf_service: + # Check systemd service + if is_systemd_service_running(conf_service): + status = 1 + else: + # Check process + if process_named_running(conf_service): + status = 1 + print(f'vyos_services,service="{conf_service}" ' + f'status={str(status)}i {str(int(time.time()))}000000000') -- cgit v1.2.3