Package DataCollector :: Package CommandParsers :: Module Unix_df_k
[hide private]
[frames] | no frames]

Source Code for Module DataCollector.CommandParsers.Unix_df_k

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2007, 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  __doc__ = """CommandParser 
15   
16  CommandParser parses the output of a command to return a datamap 
17   
18  $Id: Uname_A.py,v 1.2 2003/10/01 23:40:51 edahl Exp $""" 
19   
20  __version__ = '$Revision: 1.2 $'[11:-2] 
21   
22  import re 
23   
24  from CommandParser import CommandParser 
25   
26 -class Unix_df_k(CommandParser):
27 28 command = 'df -k' 29
30 - def condition(self, device, log):
31 pp = device.getPrimaryPath() 32 return "Linux" in pp or "Darwin" in pp
33
34 - def parse(self, device, results, log):
35 log.info("collecting filesystems from device %s" % device.id) 36 rm = self.newRelationshipMap("filesystems") 37 rlines = results.split("\n") 38 for line in rlines: 39 aline = line.split() 40 if len(aline) != 6: continue 41 try: 42 om = self.newObjectMap("ZenModel.FileSystem") 43 om['storageDevice'] = aline[0] 44 om['totalBytes'] = long(aline[1]) * 1024 45 om['usedBytes'] = long(aline[2]) * 1024 46 om['availBytes'] = long(aline[3]) * 1024 47 cap = aline[4][-1] == "%" and aline[4][:-1] or aline[4] 48 om['capacity'] = cap 49 om['mount'] = aline[5] 50 om['id'] = self.prepId(om['mount'], '-') 51 om['title'] = om['mount'] 52 rm.append(om) 53 except ValueError: pass 54 return rm
55
56 - def description(self):
57 return "get df -k from server to build filesystems"
58