Quantcast
Channel: Zenoss Community : All Content - ZenDMD
Viewing all articles
Browse latest Browse all 10

Displaying System count per Group organizer

$
0
0

I had a request recently to provide a count of devices assigned to a particular System organizer, per Group organizer.  An example:

 

Group1 has 2 Routers that are each in the System organizer of "Routers", and 4 Switches each in the System organizer of "Switches"

Group2 has 1 Router in the System organizer of "Routers", and one Server in the System organizer of "Servers"

 

I needed a zendmd script that would output a list like this:

 

Group1:

Routers: 2

Switches: 4

 

Group2:

Routers: 1

Servers: 1

 

and so on.

 

I posed this question to the irc chat room and rmatte came up with this

 

 

for g in dmd.Groups.getSubOrganizers():
groupcount = {}
for d in g.getSubDevices():
  if d.getSystemNames():
   try:
    groupcount[d.getSystemNames()[0].split('/')[1]] = groupcount[d.getSystemNames()[0].split('/')[1]] + 1
   except KeyError:
    groupcount[d.getSystemNames()[0].split('/')[1]] = 1
print "%s:" % (g.id)
for a, b in groupcount.iteritems():
  print "   %s: %s" % (a, b)
print ""

 

 

 

This works perfectly for my needs.  With rmatte's blessing, I'm dropping it here so it can help out some other folks as well.


Viewing all articles
Browse latest Browse all 10

Trending Articles