Permalink
Browse files

Chef Client 0.2

git-svn-id: http://zenpacks.zenoss.org/svn/zenpacks@844 db08cffe-75b9-45d1-af1a-46ad9ef135f6
  • Loading branch information...
0 parents commit ac820ff164802b439688debb9577b575dbc9913f Matt Ray committed Jul 20, 2010
Showing with 648 additions and 0 deletions.
  1. +16 −0 COPYRIGHT.txt
  2. +1 −0 MANIFEST.in
  3. +1 −0 ZenPacks/__init__.py
  4. +16 −0 ZenPacks/community/ChefClient/__init__.py
  5. 0 ZenPacks/community/ChefClient/modeler/__init__.py
  6. 0 ZenPacks/community/ChefClient/modeler/plugins/__init__.py
  7. 0 ZenPacks/community/ChefClient/modeler/plugins/community/__init__.py
  8. 0 ZenPacks/community/ChefClient/modeler/plugins/community/cmd/__init__.py
  9. 0 ZenPacks/community/ChefClient/modeler/plugins/community/cmd/chef/__init__.py
  10. +57 −0 ZenPacks/community/ChefClient/modeler/plugins/community/cmd/chef/cpu.py
  11. +39 −0 ZenPacks/community/ChefClient/modeler/plugins/community/cmd/chef/host.py
  12. +47 −0 ZenPacks/community/ChefClient/modeler/plugins/community/cmd/chef/memory.py
  13. +3 −0 ZenPacks/community/ChefClient/objects/objects.xml
  14. 0 ZenPacks/community/ChefClient/tests/__init__.py
  15. +63 −0 ZenPacks/community/ChefClient/tests/plugindata/chef/ubuntu.zenoss.loc/cpu
  16. +10 −0 ZenPacks/community/ChefClient/tests/plugindata/chef/ubuntu.zenoss.loc/cpu.py
  17. +179 −0 ZenPacks/community/ChefClient/tests/plugindata/chef/ubuntu.zenoss.loc/host
  18. +8 −0 ZenPacks/community/ChefClient/tests/plugindata/chef/ubuntu.zenoss.loc/host.py
  19. +111 −0 ZenPacks/community/ChefClient/tests/plugindata/chef/ubuntu.zenoss.loc/memory
  20. +3 −0 ZenPacks/community/ChefClient/tests/plugindata/chef/ubuntu.zenoss.loc/memory.py
  21. +24 −0 ZenPacks/community/ChefClient/tests/testPlugins.py
  22. +1 −0 ZenPacks/community/__init__.py
  23. +69 −0 setup.py
@@ -0,0 +1,16 @@
+All files in this directory and below are:
+
+Copyright (c) 2010 Zenoss, Inc. All rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License version 2 as published
+by the Free Software Foundation.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
@@ -0,0 +1 @@
+graft ZenPacks
@@ -0,0 +1 @@
+__import__('pkg_resources').declare_namespace(__name__)
@@ -0,0 +1,16 @@
+import Globals
+import os.path
+from Products.CMFCore.DirectoryView import registerDirectory
+from Products.ZenModel.ZenPack import ZenPackBase
+
+skinsDir = os.path.join(os.path.dirname(__file__), 'skins')
+if os.path.isdir(skinsDir):
+ registerDirectory(skinsDir, globals())
+
+class ZenPack(ZenPackBase):
+ """ ChefClient loader
+ """
+
+ packZProperties = [
+ ('zChefRole', '', 'string'),
+ ]
@@ -0,0 +1,57 @@
+import json
+from Products.DataCollector.plugins.CollectorPlugin import CommandPlugin
+from Products.DataCollector.plugins.DataMaps import MultiArgs
+
+L2MULTIPLIER = {
+ 'kB' : 1,
+ 'KB' : 1,
+ 'M' : 1024,
+ 'mB' : 1024,
+ 'MB' : 1024,
+ 'Megabytes' : 1024,
+}
+
+class cpu(CommandPlugin):
+ """
+ find the cpu information
+ """
+ maptype = "CPUMap"
+ command = 'ohai cpu'
+ compname = 'hw'
+ relname = "cpus"
+ modname = "Products.ZenModel.CPU"
+
+ def process(self, device, results, log):
+ """parse command output from this device"""
+ log.info('Processing the ohai cpu info for device %s' % device.id)
+ rm = self.relMap()
+ om = self.objectMap()
+ #results are JSON-formatted output
+ #get a JSON parser and pull out values
+ joutput = json.loads(results)
+ joutput.sort()
+ #"total"
+ number = joutput[2][1]
+ #"model_name"
+ om.description = joutput[0][1]['model_name']
+ #"vendor_id"
+ manufacturer = joutput[0][1]['vendor_id']
+ if manufacturer == 'GenuineIntel':
+ manufacturer = 'Intel'
+ om.setProductKey = MultiArgs(om.description,manufacturer)
+ #"mhz"
+ om.clockspeed = float(joutput[0][1]['mhz'])
+ #"cache_size"
+ cache_size = joutput[0][1]['cache_size']
+ cache, unit = cache_size.split()
+ om.cacheSizeL2 = int(cache) * L2MULTIPLIER.get(unit, 1)
+
+ #insert an objectMap for each CPU
+ for n in range(number):
+ om.id = str(n)
+ om.socket = str(n)
+ rm.append(om)
+
+ log.debug(rm)
+ return rm
+
@@ -0,0 +1,39 @@
+import json
+from Products.DataCollector.plugins.CollectorPlugin import CommandPlugin
+from Products.DataCollector.plugins.DataMaps import MultiArgs
+
+class host(CommandPlugin):
+ maptype = "DeviceMap"
+ compname = ""
+ command = "ohai fqdn kernel"
+
+ def process(self, device, results, log):
+ """Collect command-line information from this device"""
+ log.info("Processing the ohai host info for device %s" % device.id)
+ om = self.objectMap()
+ #results are JSON-formatted output
+ #get a JSON parser and pull out values
+ #first [] set is snmpSysName
+ fqdnresults = results[0:results.index(']')+1]
+ fqdnjson = json.loads(fqdnresults)
+ om.snmpSysName = fqdnjson[0]
+ #seond [] set is kernel info
+ kernelresults = results[results.index(']')+1:]
+ kerneljson = json.loads(kernelresults)
+ kerneljson.sort()
+ # "name"
+ om.uname = kerneljson[2][1]
+ # "machine"
+ machine = kerneljson[0][1]
+ # "os"
+ os = kerneljson[3][1]
+ # "release"
+ release = kerneljson[4][1]
+ # "version"
+ version = kerneljson[5][1]
+ om.setOSProductKey = MultiArgs(version, os)
+ # "name fqdn version release machine"
+ om.snmpDescr = om.uname+' '+om.snmpSysName+' '+version+' '+release+' '+machine
+
+ log.debug(om)
+ return om
@@ -0,0 +1,47 @@
+import json
+from Products.DataCollector.plugins.CollectorPlugin import CommandPlugin
+from Products.DataCollector.plugins.DataMaps import ObjectMap
+
+MULTIPLIER = {
+ 'kB' : 1024,
+ 'MB' : 1024 * 1024,
+ 'M' : 1024 * 1024,
+ 'Megabytes' : 1024 * 1024,
+ 'GB' : 1024 * 1024 * 1024,
+ 'G' : 1024 * 1024 * 1024,
+ 'Gigabytes' : 1024 * 1024 * 1024,
+ 'b' : 1
+}
+
+class memory(CommandPlugin):
+ """
+ find the memory
+ """
+ maptype = "FileSystemMap"
+ command = 'ohai memory'
+ compname = 'hw'
+ relname = "filesystems"
+ modname = "Products.ZenModel.Filesystem"
+
+ def process(self, device, results, log):
+ log.info('Processing the ohai memory info for device %s' % device.id)
+ maps = []
+
+ #results are JSON-formatted output
+ #get a JSON parser and pull out values
+ joutput = json.loads(results)
+ joutput.sort()
+
+ total_value = joutput[21][1][:-2]
+ total_units = joutput[21][1][-2:]
+ total_size = int(total_value) * MULTIPLIER.get(total_units, 1)
+ maps.append(ObjectMap({"totalMemory": total_size}, compname="hw"))
+
+ swap_value = joutput[20][1]['total'][:-2]
+ swap_units = joutput[20][1]['total'][-2:]
+ swap_size = int(swap_value) * MULTIPLIER.get(swap_units, 1)
+ maps.append(ObjectMap({"totalSwap": swap_size}, compname="os"))
+
+ log.debug(maps)
+ return maps
+
@@ -0,0 +1,3 @@
+<?xml version="1.0"?>
+<objects>
+</objects>
@@ -0,0 +1,63 @@
+ohai cpu
+[
+ [
+ "real",
+ 0
+ ],
+ [
+ "total",
+ 1
+ ],
+ [
+ "0",
+ {
+ "flags": [
+ "fpu",
+ "vme",
+ "de",
+ "pse",
+ "tsc",
+ "msr",
+ "pae",
+ "mce",
+ "cx8",
+ "apic",
+ "mtrr",
+ "pge",
+ "mca",
+ "cmov",
+ "pat",
+ "pse36",
+ "clflush",
+ "dts",
+ "acpi",
+ "mmx",
+ "fxsr",
+ "sse",
+ "sse2",
+ "ss",
+ "nx",
+ "lm",
+ "constant_tsc",
+ "up",
+ "arch_perfmon",
+ "pebs",
+ "bts",
+ "tsc_reliable",
+ "pni",
+ "ssse3",
+ "cx16",
+ "sse4_1",
+ "hypervisor",
+ "lahf_lm"
+ ],
+ "model": "23",
+ "model_name": "Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz",
+ "family": "6",
+ "mhz": "2395.872",
+ "vendor_id": "GenuineIntel",
+ "cache_size": "3072 KB",
+ "stepping": "6"
+ }
+ ]
+]
@@ -0,0 +1,10 @@
+{'cpu':[
+ dict(
+ compname = 'hw',
+ socket = '0',
+ clockspeed = 2395.872,
+ cacheSizeL2 = 3072,
+ description = "Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz",
+ setProductKey = ('Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz', 'Intel'),
+ ),]
+}
Oops, something went wrong.

0 comments on commit ac820ff

Please sign in to comment.