[ SEA-GHOST MINI SHELL]

Path : /proc/2/root/proc/3/cwd/var/lib/zabbix/
FILE UPLOADER :
Current File : //proc/2/root/proc/3/cwd/var/lib/zabbix/whmapi_hourly_emailstats.py

#!/usr/bin/env python2.7
###############################################
#           Email statistics generator        #
###############################################
# Generating stats from emailtrack_stats for the last hour
# ARGS:
# OUTPUT: {u'data': 
#           {u'records': 
#               [
#                   {
#                       u'DEFERCOUNT': 39952, 
#                       u'TOTALSIZE': 47420311814, 
#                       u'SUCCESSCOUNT': 283963, 
#                       u'FAILCOUNT': 199858, 
#                       u'SENDCOUNT': 448667, 
#                       u'INPROGRESSCOUNT': 416, 
#                       u'DEFERFAILCOUNT': 239810
#                   }
#               ]
#           }, 
#           u'metadata': 
#               {
#                   u'reason': u'OK', 
#                   u'version': 1, 
#                   u'command': u'emailtrack_stats', 
#                   u'result': 1, 
#                   u'overflowed': 0, 
#                   u'__chunked': 1
#               }
#       }


WHMAPI_COMMAND = "whmapi1"
API_ENDPOINT = "emailtrack_stats"
OUTPUT_FORMAT = "json"

import datetime
import json
import subprocess


def create_whmapi_cli_command(
        command = WHMAPI_COMMAND,
        api_endpoint = API_ENDPOINT,
        output_format = OUTPUT_FORMAT,
        *args,
        **kwargs
        ):
    generic_command = "{cmd} {endpoint} --output={output_format}".format(
            cmd=command,
            endpoint=api_endpoint,
            output_format=output_format
            )

    # Populate args and kwargs
    for arg in args:
        generic_command += " {arg}".foramt(arg=str(arg))
    for key, val in kwargs.items():
        generic_command += " {k}={v}".format(k=key, v=val)

    return generic_command

def execute_whmapi_call(command):
    pipe = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
    return pipe.stdout.read()


if __name__ == "__main__":
    start_time = datetime.datetime.now() - datetime.timedelta(hours=1)
    start_time = start_time.strftime('%s')
    cli = create_whmapi_cli_command(starttime=start_time)
    result = json.loads(execute_whmapi_call(cli))
    stats = result['data']['records'][0]
    output = ""
    for key, val in stats.items():
      output += "{k}={v} ".format(k=key, v=val)
    print(output)


SEA-GHOST - SHELL CODING BY SEA-GHOST