[ SEA-GHOST MINI SHELL]

Path : /proc/2/cwd/proc/self/root/proc/self/root/proc/2/task/2/cwd/var/lib/zabbix/
FILE UPLOADER :
Current File : //proc/2/cwd/proc/self/root/proc/self/root/proc/2/task/2/cwd/var/lib/zabbix/activemq_check

#!/usr/bin/env python

from argparse import ArgumentParser
from subprocess import Popen, PIPE, STDOUT
from xml.dom import minidom
import urllib2
import base64
import json

URL = 'http://localhost:8161/admin/xml/queues.jsp'

def zabbix_sender(payload, agentconfig):
    sender_command = [ '/usr/bin/zabbix_sender', '-vv', '--config', agentconfig, '--input-file', '-' ]
    result = 0

    try:
        p = Popen(sender_command, stdout = PIPE, stdin = PIPE, stderr = PIPE)
        out, err = p.communicate( input = payload )
        ret = p.wait()
        result = 1

    except Exception, e:
        err = "%s\nFailed to execute: '%s'" % (e, " ".join(sender_command))

    finally:
        if ret != 0:
            raise Exception("error returned from %s! ret: %d, out: '%s', err: '%s'" % (sender_command[0], ret, out.strip('\n'), err.strip('\n')))

    return result

def get_queues_data(url, user = None, passwd = None):

    request = urllib2.Request(url)

    if user and passwd:
       base64string = base64.encodestring('%s:%s' % (user, passwd)).replace('\n', '')
       request.add_header("Authorization", "Basic %s" % base64string)

    try:
        conn = urllib2.urlopen(request)
        data = conn.read()
        conn.close()
    except:
        raise

    dom = minidom.parseString(data)
    return dom.getElementsByTagName('queue')

def find_queues(user, passwd):
    queuenodes = get_queues_data(URL, user, passwd)
    result = []
    for node in queuenodes:
        queue = node.attributes.item(0).value
        result.append('{{ "{{#QUEUE_NAME}}": "{0}" }}'.format(queue))
    print('{{ "data": [ {} ]}}'.format(', '.join(result)))

def parse_queues(user, passwd):
    payload = ""
    queuenodes = get_queues_data(URL, user, passwd)
    for node in queuenodes:
        queue = node.attributes.item(0).value
        stats_item = node.getElementsByTagName('stats').item(0)
        consumer_count = stats_item.getAttribute('consumerCount')
        dequeue_count = stats_item.getAttribute('dequeueCount')
        enqueue_count = stats_item.getAttribute('enqueueCount')
        size = stats_item.getAttribute('size')
        payload += "-\tactivemq.consumerCount[{0}]\t{1}\n".format(queue, consumer_count)
        payload += "-\tactivemq.dequeueCount[{0}]\t{1}\n".format(queue, dequeue_count)
        payload += "-\tactivemq.enqueueCount[{0}]\t{1}\n".format(queue, enqueue_count)
        payload += "-\tactivemq.size[{0}]\t{1}\n".format(queue, size)
    return payload

def get_opts():
    parser = ArgumentParser(prog='activemq_check', usage='%(prog)s [options]')
    parser.add_argument(
                      '-l',
                      '--list',
                      action='store_true'
                      )
    parser.add_argument(
                      '-u',
                      '--user',
                      action = 'store',
                      default = 'admin',
                      help = "HTTP authentication user to use when connection. [default: admin]",
                      )
    parser.add_argument(
                      '-p',
                      '--pass',
                      action = 'store',
                      dest = 'passwd',
                      default = 'admin',
                      help = "HTTP authentication password to use when connection. [default: admin]",
                      )
    parser.add_argument(
                      '-c',
                      '--conf',
                      action = 'store',
                      default = '/etc/zabbix/zabbix_agentd.conf',
                      help = "Zabbix agent config to derive Hostname and ServerActive from. [default: %(default)s]",
                      )

    return parser.parse_args()

def main():
    args = get_opts()
    if args.list:
        find_queues(args.user, args.passwd)
    else:
        payload = parse_queues(args.user, args.passwd)
        try:
            result = zabbix_sender(
                payload     = payload,
                agentconfig = args.conf)
        except Exception as e:
            raise Exception('failed to send parsed data: %s' % e)
        else:
            print result

if __name__ == "__main__":
    main()

SEA-GHOST - SHELL CODING BY SEA-GHOST