def add_interface(self, interfaceobject): if not type(interfaceobject) == interface.zbxinterface: errmsg = 'passed interfaceobject is not the correct type must be zbxinterface but is {0}'.format( type(interfaceobject)) self.logger.critical(errmsg) raise core.WrongType(errmsg, 3) tid, tidx = self.search_interface(host=interfaceobject.host, port=interfaceobject.port) idx = interfaceobject.type if not tid: if not self.interfaceobjects.get(idx, False): self.logger.debug('First interface of type {0}'.format(idx)) self.interfaceobjects[idx] = list() # self.logger.debug('Append interface {0}'.format(idx)) self.interfaceobjects[idx].append(interfaceobject) interfaceobject.add_host(self) return True else: self.logger.warning( 'Interface {host}:{port} not added not added'.format( host=interfaceobject.host, port=interfaceobject.port)) return False
def __init__(self, api, **kwargs): super(zbxinterface, self).__init__(api) # self.logger = logger or logging.getLogger(__name__) self.logger = logging.getLogger(__name__) self.difffields = ['interfaceid', 'useip', 'ip', 'dns', 'port', 'bulk', 'type', 'hostid', 'main'] self.readonlyfields = ['interfaceid'] self.assignedhost = None for att in kwargs.keys(): if att in self.difffields + ['mask', 'host']: setattr(self, att, kwargs[att]) else: raise core.WrongType('{0} is not a valid argument'.format(att), 5) self.required_fields = [ 'dns', 'hostid', 'ip', 'main', 'port', 'type', 'useip', ] self.apicommands = { "get": "hostinterface.get", "create": "hostinterface.create", "update": "hostinterface.update", "delete": "hostinterface.delete", 'hostcreate': '' }
def add_template(self, templateobject): if not type(templateobject) == zbxtemplate: errmsg = 'passed templateobject is not the correct type must be zbxtemplate but is {0}'.format( type(templateobject)) self.logger.critical(errmsg) raise core.WrongType(errmsg, 3) self.templates[templateobject.name] = templateobject
def add_group(self, groupobject): if not type(groupobject) == group.zbxgroup: errmsg = 'passed groupobject is not the correct type must be zbxgroup but is {0}'.format( type(groupobject)) self.logger.critical(errmsg) raise core.WrongType(errmsg, 3) self.logger.info('Added group {0} (id: {1})'.format( groupobject.name, groupobject.id)) self.groupopjects[groupobject.name] = groupobject return True
def __init__(self, api, groupmask=None, **kwargs): super(zbxgroup, self).__init__(api) self.logger = logging.getLogger(__name__) self.difffields = ['groupid', 'name', 'flags', 'internal'] self.readonlyfields = ['groupid', 'flags', 'internal'] self.apicommands = { 'get': 'hostgroup.get', 'create': 'hostgroup.create', 'update': 'hostgroup.update', 'delete': 'hostgroup.delete', } for att in kwargs.keys(): if att in self.difffields + ['mask']: setattr(self, att, kwargs[att]) else: raise core.WrongType('{0} is not a valid argument'.format(att), 5)
def __init__(self, api, **kwargs): super(zbxitem, self).__init__(api) self.applications = dict() self.host = None self.apicommands = { "get": "item.get", "create": "item.create", "update": "item.update", "delete": "item.delete", } self.difffields = [ 'itemid', 'delay', 'interfaceid', 'key', 'name', 'type', 'value_type', 'data_type', 'delay_flex', 'delta', 'description', 'error', 'flags', 'formula', 'history', 'inventory_link', 'jmx_endpoint', 'ipmi_sensor', 'lastclock', 'lastns', 'lastvalue', 'logtimefmt', 'mtime', 'multiplier', 'params', 'password', 'port', 'prevvalue', 'privatekey', 'publickey', 'snmp_community', 'snmp_oid', 'snmpv3_authpassphrase', 'snmpv3_authprotocol', 'snmpv3_contextname', 'snmpv3_privprotocol', 'snmpv3_securityname', 'state', 'status', 'templateid', 'trapper_hosts', 'trends', 'units', 'username', 'valuemapid' ] self.readonlyfields = [ 'itemid', 'error', 'flags', 'lastclock', 'lastns', 'lastvalue', 'prevvalue', 'templateid', 'state' ] for att in kwargs.keys(): if att in self.difffields + ['itemid', 'mask']: setattr(self, att, kwargs[att]) else: raise core.WrongType('{0} is not a valid argument'.format(att), 5)
def __init__(self, api, **kwargs): super(zbxhost, self).__init__(api) self.logger = logging.getLogger(__name__) self.interfaceobjects = dict() self.groupopjects = dict() self.templates = dict() # self.update() self.apicommands = { "get": "host.get", "create": "host.create", "update": "host.update", "delete": "host.delete", } self.difffields = [ 'hostid', 'host', 'name', 'available', 'description', 'disable_until', 'error', 'errors_from', 'flags', 'inventory_mode', 'ipmi_authtype', 'ipmi_available', 'ipmi_disable_until', 'ipmi_error', 'ipmi_errors_from', 'ipmi_password', 'ipmi_privilege', 'ipmi_username', 'jmx_available', 'jmx_disable_until', 'jmx_error', 'jmx_errors_from', 'maintenance_from', 'maintenance_status', 'maintenance_type', 'maintenanceid', 'proxy_hostid', 'snmp_available', 'snmp_disable_until', 'snmp_error', 'snmp_errors_from', 'status', 'tls_issuer', 'tls_subject', 'tls_psk_identity', 'tls_psk' ] self.readonlyfields = [ 'hostid', 'available', 'disable_until', 'error', 'errors_from', 'flags', 'ipmi_available', 'ipmi_disable_until', 'ipmi_error', 'ipmi_errors_from', 'jmx_available', 'jmx_disable_until', 'jmx_error', 'jmx_errors_from', 'maintenance_from', 'maintenance_status', 'maintenance_type', 'maintenanceid', 'snmp_available', 'snmp_disable_until', 'snmp_error', 'snmp_errors_from', ] # if hostmask: # self.merge(hostmask) for att in kwargs.keys(): if att in self.difffields + ['hostid', 'mask']: setattr(self, att, kwargs[att]) else: raise core.WrongType('{0} is not a valid argument'.format(att), 5)
def add_host(self, hostobject): if type(hostobject) == host.zbxhost: self.assignedhost = hostobject else: raise core.WrongType('Wrong type passed to zbxinterface.add_host got {0}'.format(type(host)), '4')