[root@ZBX2-HQ externalscripts]# cat zdahua_nvr.py
from amcrest import AmcrestCamera
import sys
class DataNvr(object):
def __init__(self,name):
self.name = name
self._data_dic = {
"HF-NVR":["192.168.89.210", 80,"hehe", "hehe"],
"SY-NVR": ["192.168.33.9", 80,"haha", "hehe"],
}
self._ipaddress = self._data_dic[self.name][0]
self._port = self._data_dic[self.name][1]
self._useradmin = self._data_dic[self.name][2]
self._password = self._data_dic[self.name][3]
self.cameras = AmcrestCamera(self._ipaddress, self._port,self._useradmin, self._password).camera
@property
def storage_used(self):
used = self.cameras.storage_used[0]
"""(1639.49, 'GB')"""
return used
@property
def storage_all(self):
storage_all = self.cameras.storage_all
"""{'used_percent': 88.01, 'used': (1639.49, 'GB'), 'total': (1862.95, 'GB')}"""
return storage_all
@property
def storage_total(self):
total = self.cameras.storage_total[0]
return total
@property
def storage_used_percent(self):
percent = self.cameras.storage_used_percent
return percent
@property
def ping_alive(self):
from mass_ping import MassPing
hosts = [self._ipaddress, ]
ping = MassPing(hosts=hosts, thread_count=len(hosts), test_count=2)
return 1 if ping.each_ping(self._ipaddress) else 0
if __name__ == '__main__':
msg_name = sys.argv[1].strip()
msg_case = sys.argv[2].strip()
datanvr = DataNvr(msg_name)
if hasattr(datanvr,msg_case):
values = getattr(datanvr, msg_case)
print(values)