Guest User

ring

a guest
Jul 16th, 2010
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 KB | None | 0 0
  1.  
  2. __doc__ = """df
  3. Determine the filesystems to monitor
  4. """
  5.  
  6. import re
  7. from Products.DataCollector.plugins.CollectorPlugin import CommandPlugin
  8.  
  9. #from Products.DataCollector.plugins.CollectorPlugin import LinuxCommandPlugin
  10.  
  11. class df(CommandPlugin):
  12.     """
  13.    Run df -k to model filesystem information. Should work on most *nix.
  14.    """
  15.     maptype = "FilesystemMap"
  16.     command = '/bin/df -PTk'
  17.     compname = "os"
  18.     relname = "filesystems"
  19.     modname = "Products.ZenModel.FileSystem"
  20.  
  21.  
  22.     deviceProperties = CommandPlugin.deviceProperties + (
  23.         'zFileSystemMapIgnoreNames', 'zFileSystemMapIgnoreTypes')
  24.  
  25.     oses = ['Linux']
  26.  
  27.     def condition(self, device, log):
  28.         return device.os.uname == '' or device.os.uname in self.oses
  29.  
  30.  
  31.     def process(self, device, results, log):
  32.         log.info('Collecting filesystems for device %s' % device.id)
  33.         #log.info('Device: ', device)
  34.         from pprint import pprint
  35.         log.info(dir(device))
  36.         skipfsnames = getattr(df.deviceProperties, 'zFileSystemMapIgnoreNames', None)
  37.         skipfstypes = getattr(df.deviceProperties, 'zFileSystemMapIgnoreTypes', None)
  38.         log.info(skipfsnames)
  39.         rm = self.relMap()
  40.         rlines = results.split("\n")
  41.         bline = ""
  42.         log.info('Starting fs modeling')
  43.  
  44.         log.info(device.zFileSystemMapIgnoreNames)
  45.  
  46.         for line in rlines:
  47.             if line.startswith("Filesystem"): continue
  48.             om = self.objectMap()
  49.             spline = line.split()
  50.             if len(spline) == 1:
  51.                 bline = spline[0]
  52.                 continue
  53.             if bline:
  54.                 spline.insert(0,bline)
  55.                 bline = None
  56.             if len(spline) != 7: continue
  57.             (om.storageDevice, om.type, tblocks, u, a, p, om.mount) = spline
  58.             if skipfsnames and re.search(skipfsnames,om.mount): continue
  59.             if skipfstypes and om.type in skipfstypes:
  60.                log.info("Skipping %s (%s) as it matches zFileSystemMapIgnoreTypes.",om.mount, om.type)
  61.                continue
  62.             if tblocks == "-": om.totalBlocks = 0
  63.             else: om.totalBlocks = long(tblocks)
  64.  
  65.             om.blockSize = 1024
  66.             om.id = self.prepId(om.mount)
  67.             rm.append(om)
  68.         return rm
Advertisement
Add Comment
Please, Sign In to add comment