def inner(driver): try: q = Query() yield q.connect(eventContext, 1, hostname, creds) driver.next() log.info("Query sent") yield q.query(query) result = driver.next() class_name = '' while 1: yield result.fetchSome() if not driver.next(): break for obj in driver.next(): props = [p for p in obj.__dict__.keys() if not p.startswith('_')] if obj._class_name != class_name: class_name = obj._class_name print obj._class_name print repr(props) d = {} for p in props: d[p]=getattr(obj,p) print "-------------" pprint.pprint(d) #print repr([getattr(obj, p) for p in props]) q.close() except Exception, ex: log.exception(ex)
def inner(driver): try: q = Query() yield q.connect(eventContext, 1, hostname, creds) driver.next() log.info("Query sent") yield q.query(query) result = driver.next() class_name = '' while 1: yield result.fetchSome() if not driver.next(): break for obj in driver.next(): props = [ p for p in obj.__dict__.keys() if not p.startswith('_') ] if obj._class_name != class_name: class_name = obj._class_name print obj._class_name print repr(props) d = {} for p in props: d[p] = getattr(obj, p) print "-------------" pprint.pprint(d) #print repr([getattr(obj, p) for p in props]) q.close() except Exception, ex: log.exception(ex)
class WMIClient(BaseClient): def __init__(self, device, datacollector=None, plugins=[]): BaseClient.__init__(self, device, datacollector) self.device = device self.host = device.id self._wmi = None if socket.getfqdn().lower() == device.id.lower(): self.host = "." device.zWinUser = device.zWinPassword = "" elif device.manageIp is not None: self.host = device.manageIp self.name = device.id self.user = device.zWinUser self.passwd = device.zWinPassword self.datacollector = datacollector self.plugins = plugins self.results = [] def connect(self): log.debug("connect to %s, user %r", self.host, self.user) if not self.user: log.warning("Windows login name is unset: " "please specify zWinUser and " "zWinPassword zProperties before adding devices.") raise BadCredentials("Username is empty") self._wmi = Query() creds = '%s%%%s' % (self.user, self.passwd) return self._wmi.connect(eventContext, self.device.id, self.host, creds) def close(self): if self._wmi: self._wmi.close() def query(self, queries): def inner(driver): try: queryResult = {} for tableName, query in queries.items(): query = query.replace("\\", "\\\\") yield self._wmi.query(query) result = driver.next() queryResult[tableName] = [] while 1: more = None yield result.fetchSome() try: more = driver.next() except WMIFailure, ex: msg = 'Received %s from query: %s' # Look for specific errors that should be equated # to an empty result set. if str(ex) in ( "NT code 0x80041010", "WBEM_E_INVALID_CLASS", ): log.debug(msg % (ex, query)) else: log.error(msg % (ex, query)) raise if not more: break queryResult[tableName].extend(more) yield defer.succeed(queryResult) driver.next() except Exception, ex: log.debug("Exception collecting query: %s", str(ex)) raise
class WMIClient(BaseClient): def __init__(self, device, datacollector=None, plugins=[]): BaseClient.__init__(self, device, datacollector) self.device = device self.host = device.id self._wmi = None if socket.getfqdn().lower() == device.id.lower(): self.host = "." device.zWinUser = device.zWinPassword = "" elif device.manageIp is not None: self.host = device.manageIp self.name = device.id self.user = device.zWinUser self.passwd = device.zWinPassword self.datacollector = datacollector self.plugins = plugins self.results = [] def connect(self): log.debug("connect to %s, user %r", self.host, self.user) if not self.user: log.warning("Windows login name is unset: " "please specify zWinUser and " "zWinPassword zProperties before adding devices.") raise BadCredentials("Username is empty") self._wmi = Query() creds = '%s%%%s' % (self.user, self.passwd) return self._wmi.connect(eventContext, self.device.id, self.host, creds) def close(self): if self._wmi: self._wmi.close() def query(self, queries): def inner(driver): try: queryResult = {} for tableName, query in queries.items(): query = query.replace ("\\", "\\\\") yield self._wmi.query(query) result = driver.next() queryResult[tableName] = [] while 1: more = None yield result.fetchSome() try: more = driver.next() except WMIFailure, ex: msg = 'Received %s from query: %s' # Look for specific errors that should be equated # to an empty result set. if str(ex) in ( "NT code 0x80041010", "WBEM_E_INVALID_CLASS", ): log.debug(msg % (ex, query)) else: log.error(msg % (ex, query)) raise if not more: break queryResult[tableName].extend(more) yield defer.succeed(queryResult) driver.next() except Exception, ex: log.debug("Exception collecting query: %s", str(ex)) raise