Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[change] NetJSON DeviceMonitoring compliance #2 #62

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions netengine/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def __repr__(self):
"""returns unicode string represantation"""
return self.__str__()

def validate(self):
def validate(self, *args, **kwargs):
raise NotImplementedError('Not implemented')

def to_dict(self):
def to_dict(self, autowalk=True):
raise NotImplementedError('Not implemented')

def to_json(self, **kwargs):
dictionary = self.to_dict()
def to_json(self, autowalk=True, **kwargs):
dictionary = self.to_dict(autowalk=autowalk)
return json.dumps(dictionary, **kwargs)

@property
Expand Down
2 changes: 1 addition & 1 deletion netengine/backends/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_interfaces(self):
},
]

def to_dict(self):
def to_dict(self, *args, **kwargs):
return self._dict(
{
'name': 'dummy',
Expand Down
152 changes: 152 additions & 0 deletions netengine/backends/schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# NetJSON DeviceMonitoring schema,
# https://github.com/netjson/netjson/blob/master/schema/device-monitoring.json
schema = {
'$schema': 'http://json-schema.org/draft-07/schema#',
'$id': 'https://raw.githubusercontent.com/netjson/netjson/master/schema/device-monitoring.json',
'title': 'NetJSON Device Monitoring',
'description': 'Monitoring information sent by a device.',
'type': 'object',
'additionalProperties': True,
'required': ['type'],
'properties': {
'type': {'type': 'string', 'enum': ['DeviceMonitoring']},
'general': {
'type': 'object',
'title': 'General',
'additionalProperties': True,
'properties': {
'local_time': {'type': 'integer'},
'uptime': {'type': 'integer'},
},
},
'resources': {
'type': 'object',
'title': 'Resources',
'additionalProperties': True,
'properties': {
'load': {
'type': 'array',
'items': {'type': 'number', 'minItems': 3, 'maxItems': 3},
},
'memory': {
'id': 'memory',
'type': 'object',
'properties': {
'total': {'type': 'integer'},
'free': {'type': 'integer'},
'buffered': {'type': 'integer'},
'cache': {'type': 'integer'},
},
},
'swap': {
'type': 'object',
'properties': {
'total': {'type': 'integer'},
'free': {'type': 'integer'},
},
},
'connections': {
'type': 'object',
'properties': {
'ipv4': {
'type': 'object',
'properties': {
'tcp': {'type': 'integer'},
'udp': {'type': 'integer'},
},
},
'ipv6': {
'type': 'object',
'properties': {
'tcp': {'type': 'integer'},
'udp': {'type': 'integer'},
},
},
},
},
'processes': {
'type': 'object',
'properties': {
'running': {'type': 'integer'},
'sleeping': {'type': 'integer'},
'blocked': {'type': 'integer'},
'zombie': {'type': 'integer'},
'stopped': {'type': 'integer'},
'paging': {'type': 'integer'},
},
},
'cpu': {
'type': 'object',
'properties': {
'frequency': {'type': 'integer'},
'user': {'type': 'integer'},
'system': {'type': 'integer'},
'nice': {'type': 'integer'},
'idle': {'type': 'integer'},
'iowait': {'type': 'integer'},
'irq': {'type': 'integer'},
'softirq': {'type': 'integer'},
},
},
'flash': {
'type': 'object',
'properties': {
'total': {'type': 'integer'},
'free': {'type': 'integer'},
},
},
'storage': {
'type': 'object',
'properties': {
'total': {'type': 'integer'},
'free': {'type': 'integer'},
},
},
},
},
'interfaces': {
'type': 'array',
'title': 'Interfaces',
'uniqueItems': True,
'additionalItems': True,
'items': {
'type': 'object',
'title': 'Interface',
'additionalProperties': True,
'required': ['name'],
'properties': {
'name': {'type': 'string'},
'uptime': {'type': 'integer'},
'statistics': {
'type': 'object',
'properties': {
'collisions': {'type': 'integer'},
'rx_frame_errors': {'type': 'integer'},
'tx_compressed': {'type': 'integer'},
'multicast': {'type': 'integer'},
'rx_length_errors': {'type': 'integer'},
'tx_dropped': {'type': 'integer'},
'rx_bytes': {'type': 'integer'},
'rx_missed_errors': {'type': 'integer'},
'tx_errors': {'type': 'integer'},
'rx_compressed': {'type': 'integer'},
'rx_over_errors': {'type': 'integer'},
'tx_fifo_errors': {'type': 'integer'},
'rx_crc_errors': {'type': 'integer'},
'rx_packets': {'type': 'integer'},
'tx_heartbeat_errors': {'type': 'integer'},
'rx_dropped': {'type': 'integer'},
'tx_aborted_errors': {'type': 'integer'},
'tx_packets': {'type': 'integer'},
'rx_errors': {'type': 'integer'},
'tx_bytes': {'type': 'integer'},
'tx_window_errors': {'type': 'integer'},
'rx_fifo_errors': {'type': 'integer'},
'tx_carrier_errors': {'type': 'integer'},
},
},
},
},
},
},
}
Loading