diff --git a/qyt_devnet/qyt_cisco_cmd.py b/qyt_devnet/qyt_cisco_cmd.py index d900548..b271a7b 100644 --- a/qyt_devnet/qyt_cisco_cmd.py +++ b/qyt_devnet/qyt_cisco_cmd.py @@ -43,11 +43,8 @@ def show(self, show_cmds): finally: self.client.close() - def config(self, config_cmds): + def config(self, config_cmds, enable='Cisc0123', verbose=True, wait_time=2): try: - enable = 'Cisc0123' - wait_time = 2 - verbose = True chan = self.client.invoke_shell() chan.send('term len 0\n') time.sleep(1) @@ -77,6 +74,6 @@ def config(self, config_cmds): password = 'Cisc0123' client1 = QYTCiscoSSH(hostname=r1, username=username, password=password) # print(client1.show_run()) - cmds = ['show ver', 'show ip int br', ''] + cmds = ['show ver', 'configure terminal', 'router ospf 1', 'network 1.1.1.1 0.0.0.0 area 0', ''] # print(client1.show(cmds)) client1.config(cmds) diff --git a/qyt_devnet/qyt_cisco_snmp.py b/qyt_devnet/qyt_cisco_snmp.py index b76b492..1814c56 100644 --- a/qyt_devnet/qyt_cisco_snmp.py +++ b/qyt_devnet/qyt_cisco_snmp.py @@ -25,9 +25,15 @@ def location(self): def cpu_usage(self): return int(snmpv2_get(self.ip, self.ro, "1.3.6.1.4.1.9.9.109.1.1.1.1.3.7", port=self.port)[1]) - def mem_usage(self): + def mem_usage_used(self): return int(snmpv2_get(self.ip, self.ro, "1.3.6.1.4.1.9.9.109.1.1.1.1.12.7", port=self.port)[1]) + def mem_usage_free(self): + return int(snmpv2_get(self.ip, self.ro, "1.3.6.1.4.1.9.9.109.1.1.1.1.13.7", port=self.port)[1]) + + def mem_usage_percent(self): + return int(self.mem_usage_used()) / (int(self.mem_usage_used()) + int(self.mem_usage_free())) * 100 + def get_ifs(self): return [if_name[1] for if_name in snmpv2_getnext(self.ip, self.ro, "1.3.6.1.2.1.2.2.1.2", port=161)] @@ -53,8 +59,12 @@ def get_if_out_bytes(self): print(snmp_client.location()) # CPU利用率 print(snmp_client.cpu_usage()) - # 内存利用率 - print(snmp_client.mem_usage()) + # 内存使用 + print(snmp_client.mem_usage_used()) + # 内存空闲 + print(snmp_client.mem_usage_free()) + # 内存使用率 + print('{:.1f}'.format(snmp_client.mem_usage_percent())) # 接口清单 print(snmp_client.get_ifs()) # 接口速率