Created
March 11, 2014 07:38
-
-
Save njordr/9481215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Zato | |
from zato.server.service import Service | |
from subprocess import Popen, PIPE | |
import locale | |
import re,os | |
from datetime import date, datetime | |
import json,random,sys | |
from fabric.api import run,hide,env | |
from fabric.tasks import execute | |
class ZimbraQueuesDetails(Service): | |
def retrieveQueues(self): | |
pattern = re.compile('.*TOTAL.*') | |
ret = {} | |
ret['queues'] = {} | |
self.logger.info('queues-loop for queues') | |
out = '' | |
for queue in ['active','deferred']: | |
with hide('output','running','warnings'): | |
out = run("/opt/zimbra/bin/qshape "+queue) | |
out = out.split('\n') | |
for line in out: | |
if(pattern.match(line)): | |
line = line.split() | |
ret['queues'][queue] = int(line[1]) | |
if(ret['queues'][queue] > 0): | |
c = 0 | |
name = queue+'-details' | |
ret[name] = {} | |
for line in out: | |
if(c<2): | |
c += 1 | |
continue | |
if(line.strip() != ''): | |
line = line.split() | |
ret[name][line[0]] = int(line[1]) | |
env['queues'] = ret | |
def handle(self): | |
execute(retrieveQueues, hosts=["zimbra@10.0.1.24"]) | |
ret = env['queues'] | |
ret['producer'] = 'postfix' | |
self.logger.info(ret) | |
self.logger.debug('queues-start sending') | |
#self.send_output(ret, self.config['queue_index'], self.config['queue_type'], mq_routing_key) | |
self.logger.debug('queues-end sending') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment