emilvonck / telegraf-exec-fortiswitch Goto Github PK
View Code? Open in Web Editor NEWCollection of scripts that can be used to retrieve data from fortiswitches by telegraf.
License: MIT License
Collection of scripts that can be used to retrieve data from fortiswitches by telegraf.
License: MIT License
/api/v2/monitor/switch/modules-status
Example
def _property_extractors(self):
# noqa: D102
extractors = {
"system_status": self._get_system_status(),
"capabilities": self._get_switch_capabilities(),
}
for k, v in extractors.items():
setattr(self, f"_{k}", v)
@property
def system_part_number(self):
# noqa: D102
return self._system_status["system_part_number"]
Add in the init method
class FortiSwitch:
"""Class for interacting with the FortiSwitchOS API."""
def __init__(self, host: str, username: str, password: str, verify: bool = True):
"""Initializor for the class.
Args:
host (str): Host for the API, IP or DNSname.
username (str): Username.
password (str): Password.
verify (bool, optional): Whether to verify SSL certificates or not. Defaults to True.
"""
self.host = host
self.username = username
self.password = password
self._verify = verify
data returned from get_system_psu_status is inconsistent
Example
[{
"name": "PSU1",
"status": "OK"
}, {
"name": "PSU2",
"connection": "Not inserted"
}]
Would be better if the method returned something like this instead, so we kan make a influx key for "name" and _value will be "status"
[{
"name": "PSU1",
"status": "OK"
}, {
"name": "PSU2",
"status": "Not inserted"
}]
{
'status': 'ok',
'temperature': {'value': 33.039062, 'unit': 'C'},
'voltage': {'value': 3.1971, 'unit': 'volts'},
'lanes': [
{'lane': 0, 'alarm-flags': '0x0040', 'warning-flags': '0x0040', 'laser-bias': {'value': 3.5136, 'unit': 'mAmps'}, 'tx-power': {'value': 0.932115, 'unit': 'dBm'}, 'rx-power': {'value': '-Infinity', 'unit': 'dBm'}},
{'lane': 1, 'alarm-flags': '0x0040', 'warning-flags': '0x0040', 'laser-bias': {'value': 3.7312, 'unit': 'mAmps'}, 'tx-power': {'value': 0.545748, 'unit': 'dBm'}, 'rx-power': {'value': '-Infinity', 'unit': 'dBm'}},
{'lane': 2, 'alarm-flags': '0x0040', 'warning-flags': '0x0040', 'laser-bias': {'value': 3.488, 'unit': 'mAmps'}, 'tx-power': {'value': 1.137429, 'unit': 'dBm'}, 'rx-power': {'value': '-Infinity', 'unit': 'dBm'}},
{'lane': 3, 'alarm-flags': '0x0040', 'warning-flags': '0x0040', 'laser-bias': {'value': 3.8144, 'unit': 'mAmps'}, 'tx-power': {'value': -0.448416, 'unit': 'dBm'}, 'rx-power': {'value': '-Infinity', 'unit': 'dBm'}}
],
'options': {'hex': '0x0023', 'values': ['TX_DISABLE', 'TX_FAULT', 'TX_POWER_LEVEL3']},
'options-status': {'hex': '0x0020', 'values': ['TX_POWER_LEVEL3']},
'interface': 'port52'
}
to something like this
{
'status': 'ok',
'temperature': {'value': 37.417969, 'unit': 'C'},
'voltage': {'value': 3.3005, 'unit': 'volts'},
'lane_0': 'alarm-flags': '0x0040', 'warning-flags': '0x0040', 'laser-bias': {'value': 3.5136, 'unit': 'mAmps'}, 'tx-power': {'value': 0.932115, 'unit': 'dBm'}, 'rx-power': {'value': '-Infinity', 'unit': 'dBm'}},
'lane_1': and so on,
'lane_2': and so on,
'lane_3': {and so on,
'options': {'hex': '0x000F', 'values': ['TX_DISABLE', 'TX_FAULT', 'RX_LOSS', 'TX_POWER_LEVEL1']},
'options-status': {'hex': '0x0008', 'values': ['TX_POWER_LEVEL1']},
'interface': 'port1'
},
can be fetched from https://{{host}}/api/v2/monitor/switch/capabilities
{
"http_method":"GET",
"results":{
"fortiswitch":[
{
"system-info":{
"model":"FortiSwitch-108E-FPOE",
"version":"v7.2.2,build0419,220902 (GA)",
Something like this would be nice
❯ python fortiswitch_cli.py --help
usage: fortiswitch_cli [options]
Fetch data from FortiSwitch API
optional arguments:
-h, --help show this help message and exit
--host HOST FortiSwitch API host. (default: None)
--port PORT Destination port for FortiSwitch API host (default: 443)
--username USERNAME FortiSwitch username. (default: None)
--password PASSWORD FortiSwitch password. (default: None)
--cls_method CLS_METHOD
FortiSwitch class method: get_switch_poe_status, get_switch_port_state,
get_switch_port_statistics, get_switch_properties, get_system_cpu_usage,
get_system_fan_status, get_system_mem_usage, get_system_pcb_temp,
get_system_poe_status, get_system_psu_status, get_system_upgrade_status
(default: None)
--ignore_ssl Skip SSL certificate verification. (default: True)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.