-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraytek-exporter-test.py
55 lines (40 loc) · 1.9 KB
/
draytek-exporter-test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from netmiko import ConnectHandler
from netmiko.ssh_exception import NetMikoTimeoutException,NetMikoAuthenticationException
from paramiko.ssh_exception import SSHException
from http.server import HTTPServer
import re
import requests
from netmiko import ConnectHandler
import logging
from datetime import datetime, timedelta
from netmiko.ssh_exception import NetMikoTimeoutException,NetMikoAuthenticationException
from paramiko.ssh_exception import SSHException
logging.basicConfig(filename="/home/tainn/draytek_exporter/draytek_exporter.log", level=logging.DEBUG)
vigor_draytek_3900 = {
'device_type': 'cisco_ios',
'host': '192.168.1.1',
'username': 'admin',
'password': 'admin',
'port' : 22,
'secret': 'admin',
}
mode_enable = 'enable'
net_connect_device = ConnectHandler(**vigor_draytek_3900)
net_connect_device.enable()
command_show_system = 'status system'
command_show_process = 'status process'
result_run_command_process = ''
result_run_command_system = net_connect_device.send_command(mode_enable, expect_string=r'Entering enable mode...')
result_run_command_system += net_connect_device.send_command(command_show_system, expect_string=r'#')
#print(result_run_command_system)
[Model,Hardware_Version,Firmware_Version,Build_Date_Time,Revision,System_up_Time,CPU_usage,Memory_Size,Memory_Usage,Current_System_Time,EEPROM_Version,Bootloader_Version] = re.findall("\d.+", result_run_command_system)
result_run_command_process += net_connect_device.send_command(command_show_process, expect_string=r'#')
#print(result_run_command_process)
process = re.findall("\d.+", result_run_command_process)
[memory_used, memory_free, memory_shards, memory_buffer, memory_cached] = re.findall('\d+', process[0])
print("used : "+memory_used)
print("free : "+memory_free)
print("shared : "+memory_shards)
print("buff : "+memory_buffer)
print("cached : "+memory_cached)
net_connect_device.disconnect()