[ SEA-GHOST MINI SHELL]

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

#!/usr/bin/python
import json
import re
import subprocess
import sys
from argparse import ArgumentParser

BINARYPATH = "/usr/sbin/megasasctl"


def get_opts():
    parser = ArgumentParser(
        usage='%(prog)s -d array|disk | -s <array ID>|<disk ID>',
        description='This program gets RAID array info using megasasctl tool'
    )
    parser.add_argument(
        "-d", "--discover",
        action="store",
        dest="discover",
        choices=['array', 'disk'],
        help="Return JSON object with discovered arrays or disks"
    )
    parser.add_argument(
        "-s", "--status",
        action="store",
        dest="status",
        help="Get status of given array or disk",
    )
    args = parser.parse_args()
    if args.discover or args.status:
        return args
    else:
        parser.print_help()
        sys.exit(0) 


def get_output(cmd):
    try:
        res = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        output, error = res.communicate()
        if error:
            print error.strip()
            sys.exit(2)
    except OSError as err:
        print "Error: could not find the executable {}. Check if it exists".format(BINARYPATH)
        sys.exit(2)
    return output.splitlines()


def return_arraylist(output):
    array_list = []
    for line in output:
        if re.match(r'^[a-z][0-9]+[a-z][0-9]+\s.*$', line.strip()):
            array = line.split()
            new_array = {
                "{#ID}": array[0],
                "{#TYPE}": ' '.join(array[2:3]),
                "{#SIZE}": array[1],
                "{#STATUS}": array[-1]
            }
            array_list.append(new_array)
    return array_list


def return_disklist(output):
    disk_list = []
    for line in output:
        if re.match(r'^[a-z][0-9]+[a-z][0-9\*]+[a-z][0-9]+\s.*$', line.strip()):
            disk = line.split()
            # Let's hack... Some disk may report smart error after status
            # Get theses errors, join them into one list item and place it
            # before status
            errindex = False
            try:
                errindex = disk.index('errs:')
            except ValueError:
                pass
            if errindex:
                disk.insert(errindex - 1, ' '.join(disk[errindex:]))
                disk = disk[:errindex + 1]
            if re.match(r'^errs:.*$', disk[-2]):
                new_disk = {
                    "{#ID}": disk[0],
                    "{#MODEL}": ' '.join(disk[1:-3]),
                    "{#STATUS}": disk[-1],
                    "{#SARNINGS}": disk[-2]
                }
            else:
                new_disk = {
                    "{#ID}": disk[0],
                    "{#MODEL}": ' '.join(disk[1:-2]),
                    "{#STATUS}": disk[-1]
                }
            disk_list.append(new_disk)
    return disk_list


def main():
    opts = get_opts()
    cmd = [BINARYPATH, '-v']
    output = get_output(cmd)
    if opts.discover == 'array':
        arrays = return_arraylist(output)
        print(json.dumps({"data": arrays}, indent=4))
        sys.exit()
    if opts.discover == 'disk':
        disks = return_disklist(output)
        print(json.dumps({"data": disks}, indent=4))
        sys.exit()
    if opts.status:
        arrays = return_arraylist(output)
        disks = return_disklist(output)
        for array in arrays:
            if array["{#ID}"] == opts.status:
                print array["{#STATUS}"]
                sys.exit()
        for disk in disks:
            if disk["{#ID}"] == opts.status:
                print disk["{#STATUS}"]
                sys.exit()
        print "ZBX_NOTSUPPORTED"


if __name__ == "__main__":
    main()


SEA-GHOST - SHELL CODING BY SEA-GHOST