Commit f70cb608 authored by MaksimSmile13's avatar MaksimSmile13

Custom

parent 26a0e597
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Hikvision.DSKV8.get_chassis_id
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
import xml.etree.ElementTree as ElementTree
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetchassisid import IGetChassisID
class Script(BaseScript):
name = "Hikvision.DS2CD.get_chassis_id"
cache = True
interface = IGetChassisID
def execute(self):
v = self.http.get("/PSIA/System/deviceInfo", json=False, cached=True, use_basic=True)
root = ElementTree.fromstring(v)
for child in root:
key = child.tag.split("}")[1][0:]
if key == "macAddress":
mac = child.text
break
return {
"first_chassis_mac": mac,
"last_chassis_mac": mac
}
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Hikvision.DSKV8.get_interfaces
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
import xml.etree.ElementTree as ElementTree
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetinterfaces import IGetInterfaces
from noc.core.ip import IPv4, IPv6
from noc.core.script.http.base import HTTPError
class Script(BaseScript):
name = "Hikvision.DS2CD.get_interfaces"
interface = IGetInterfaces
def execute(self):
r = []
ns = {'ns': 'urn:psialliance-org'}
v = self.http.get("/PSIA/System/Network/interfaces", cached=True, use_basic=True)
root = ElementTree.fromstring(v)
# mac = self.scripts.get_chassis_id()[0]["first_chassis_mac"]
for o in root:
o_id = o.find("ns:id", ns).text
name = "eth%s" % o_id
iface = {
"name": name,
"type": "physical",
"admin_status": True,
"oper_status": True
}
sub = {
"name": name,
"admin_status": True,
"oper_status": True,
"enabled_afi": []
}
exten = o.find("ns:Extensions", ns)
link = exten.find("ns:Link", ns)
mac = link.find("ns:MACAddress",ns).text
#mac = self.scripts.get_chassis_id()[0]["first_chassis_mac"]
if mac:
sub["mac"] = mac
iface["mac"] = mac
ip = o.find("ns:IPAddress", ns)
print ip
# for ip in ip_addresses:
afi = ip.find("ns:ipVersion", ns).text
if afi in ["v4", "dual"]:
if "IPv4" not in sub["enabled_afi"]:
sub["enabled_afi"] += ["IPv4"]
ip_address = "%s/%s" % (
ip.find("ns:ipAddress", ns).text, IPv4.netmask_to_len(
ip.find("ns:subnetMask", ns).text
)
)
if "ipv4_addresses" in sub:
sub["ipv4_addresses"] += [ip_address]
else:
sub["ipv4_addresses"] = [ip_address]
if afi in ["v6"]:
if "IPv6" not in sub["enabled_afi"]:
sub["enabled_afi"] += ["IPv6"]
ip_address = IPv6(
ip.find("ns:ipAddress", ns).text, netmask=ip.find("ns:subnetMask", ns).text
).prefix
iface["subinterfaces"] = [sub]
r += [iface]
return [{"interfaces": r}]
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Hikvision.DSKV8.get_version
# ---------------------------------------------------------------------
# Copyright (C) 2007-2019 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
# Python modules
import re
import xml.etree.ElementTree as ElementTree
# NOC modules
from noc.core.script.base import BaseScript
from noc.sa.interfaces.igetversion import IGetVersion
class Script(BaseScript):
name = "Hikvision.DS2CD.get_version"
interface = IGetVersion
cache = True
rx_date = re.compile(r"(?P<yy>\d\d)(?P<mm>\d\d)(?P<dd>\d\d)")
def execute(self):
ns = {'psia': 'urn:psialliance-org',
'std-cgi': 'http://www.std-cgi.com/ver20/XMLSchema',
'hikvision': 'http://www.hikvision.com/ver20/XMLSchema'}
v = self.http.get("/PSIA/System/deviceInfo", use_basic=True)
if "xmlns" in v:
ns['ns'] = ns["psia"]
elif "www.hikvision.com" in v:
ns['ns'] = ns["hikvision"]
else:
ns['ns'] = ns["psia"]
root = ElementTree.fromstring(v)
for r in root:
print r
return {
"vendor": 'Hikvision',
"platform": root.find("psia:model", ns).text,
"version": root.find("psia:firmwareVersion", ns).text,
"attributes": {
# "Boot PROM": match.group("bootprom"),
"Build Date": root.find("psia:firmwareReleasedDate", ns).text,
"HW version": root.find("psia:firmwareVersion", ns).text,
"Serial Number": root.find("psia:serialNumber", ns).text
# "Firmware Type":
}
}
# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------
# Vendor: Hikvision
# OS: DS2CD
# ---------------------------------------------------------------------
# Copyright (C) 2007-2018 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
from noc.core.profile.base import BaseProfile
class Profile(BaseProfile):
name = "Hikvision.DS2CD"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment