From add08e8ace72882f3e349ee57d2cc8cecec1aae8 Mon Sep 17 00:00:00 2001 From: Eric Krichbaum Date: Sat, 20 Apr 2024 16:26:52 -0500 Subject: [PATCH] add get_environment data --- napalm_panos/panos.py | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/napalm_panos/panos.py b/napalm_panos/panos.py index 8e9728d..ceaf505 100644 --- a/napalm_panos/panos.py +++ b/napalm_panos/panos.py @@ -796,3 +796,62 @@ def extract_ip_info(parsed_intf_dict): ip_interfaces.update(ip_info) return ip_interfaces + + def _get_environmentals(self): + """get temps/fans/powers""" + candidate_command = "" + self.device.op(cmd=candidate_command) + raw = str(self.device.xml_root()) + t=xmltodict.parse(raw) + data=t["response"]["result"] + return data + + def _get_resources(self): + candidate_command = "" + self.device.op(cmd=candidate_command) + raw = str(self.device.xml_root()) + t=xmltodict.parse(raw) + running=t["response"]["result"] + return running + + def get_environment(self): + fan_dict = {} + temp_dict = {} + cpu_dict = {} + psu_dict = {} + mem_dict = {} + t = self._get_environmentals() + # parse out t to get temps/fans/power + for fan in t["fan"]["Slot1"]["entry"]: + value = "True" + if fan["alarm"] == "True": + value = "False" + fan_dict.update({fan["description"]: { "status": value }}) + + for temp in t["thermal"]["Slot1"]["entry"]: + temp_dict.update({temp["description"]: { "temperature": temp["DegreesC"] }}) + + for power in t["power-supply"]["Slot1"]["entry"]: + value = "True" + if power["alarm"] == "True": + value = "False" + psu_dict.update({power["description"]: { "status": value }}) + + t = self._get_resources() + x=t.split("\n") + tcpu=x[2].split() + tmem=x[3].split() + mem_dict.update({'available_ram': tmem[5], 'used_ram': tmem[7]}) + cpu_dict.update({'user': {'%usage': tcpu[1]}}) + cpu_dict.update({'system': {'%usage': tcpu[3]}}) + cpu_dict.update({'nice': {'%usage': tcpu[5]}}) + cpu_dict.update({'idle': {'%usage': tcpu[7]}}) + + environment = { + 'fans': fan_dict, + 'temperature': temp_dict, + 'power': psu_dict, + 'cpu': cpu_dict, + 'memory': mem_dict + } + return environment