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, 2008 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 log.debug('Starting watcher on %s', device.id) 25 self.wmi = Query() 26 self.device = device 27 self.queryString = query 28 self.enum = None
29
30 - def connect(self):
31 name = self.device.id 32 def inner(driver): 33 try: 34 log.debug('connecting to %s', name) 35 d = self.device 36 yield self.wmi.connect(eventContext, 37 d.manageIp, 38 '%s%%%s' % (d.zWinUser, d.zWinPassword)) 39 driver.next() 40 log.debug('connected to %s sending query', name) 41 yield self.wmi.notificationQuery(self.queryString) 42 self.enum = driver.next() 43 log.debug('got query response from %s', name) 44 except Exception, ex: 45 log.exception(ex) 46 raise
47 return drive(inner)
48
49 - def getEvents(self, timeout=0, chunkSize=1):
50 assert self.enum 51 name = self.device.id 52 log.debug("Fetching events for %s", name) 53 def fetched(result): 54 log.debug("Events fetched for %s", name) 55 return result
56 try: 57 result = self.enum.fetchSome(timeoutMs=timeout, chunkSize=chunkSize) 58 result.addCallback(fetched) 59 return result 60 except Exception, ex: 61 raise ex 62
63 - def close(self):
64 self.wmi.close()
65