Package ZenWin :: Module Watcher
[hide private]
[frames] | no frames]

Source Code for Module ZenWin.Watcher

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2007-2009 Zenoss Inc. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify it 
 7  # under the terms of the GNU General Public License version 2 as published by 
 8  # the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
11  # 
12  ########################################################################### 
13   
14  from pysamba.twisted.reactor import eventContext 
15  from pysamba.wbem.Query import Query 
16  from Products.ZenUtils.Driver import drive 
17   
18  import logging 
19  log = logging.getLogger("zen.Watcher") 
20   
21 -class Watcher:
22
23 - def __init__(self, device, query):
24 self.wmi = Query() 25 self.device = device 26 self.queryString = query 27 self.enum = None 28 self.busy = False 29 self.closeRequested = False 30 log.debug("Starting watcher on %s", device.id)
31
32 - def connect(self):
33 self.busy = True 34 35 def finished(result): 36 self.busy = False 37 if self.closeRequested: 38 self.close() 39 return result
40 41 def inner(driver): 42 log.debug("connecting to %s", self.device.id) 43 d = self.device 44 45 yield self.wmi.connect(eventContext, 46 d.manageIp, 47 "%s%%%s" % (d.zWinUser, d.zWinPassword)) 48 driver.next() 49 50 log.debug("connected to %s sending query", self.device.id) 51 yield self.wmi.notificationQuery(self.queryString) 52 53 self.enum = driver.next() 54 log.debug("got query response from %s", self.device.id)
55 56 return drive(inner).addBoth(finished) 57
58 - def getEvents(self, timeout=0, chunkSize=10):
59 assert self.enum 60 self.busy = True 61 log.debug("Fetching events for %s", self.device.id) 62 63 def fetched(result): 64 log.debug("Events fetched for %s", self.device.id) 65 return result
66 67 def finished(result): 68 self.busy = False 69 if self.closeRequested: 70 self.close() 71 return result 72 73 result = self.enum.fetchSome(timeoutMs=timeout, chunkSize=chunkSize) 74 result.addBoth(finished) 75 result.addCallback(fetched) 76 return result 77
78 - def close(self):
79 if self.busy: 80 log.debug("close requested on busy WMI Query for %s; deferring", 81 self.device.id) 82 self.closeRequesed = True 83 elif self.wmi: 84 log.debug("closing WMI Query for %s", self.device.id) 85 self.wmi.close() 86 self.wmi = None
87