neptune/core/lib/manage/threshold.py

230 lines
4.9 KiB
Python

from django.conf import settings
from core.lib.threshold import threshold_request
def get_irc_stats():
url = "irc/stats"
payload = {}
stats = threshold_request(url, payload)
if not stats:
return {}
return stats
def get_irc_networks():
url = "irc/networks"
payload = {}
networks = threshold_request(url, payload)
if not networks:
return {}
return networks
def get_irc_network(net):
url = f"irc/network/{net}"
payload = {}
network = threshold_request(url, payload)
if not network:
return {}
return network
def edit_irc_network(net, data):
url = f"irc/network/{net}/edit"
payload = dict(data)
result = threshold_request(url, payload)
return result
def change_network_status(net, num, status):
url = f"irc/network/{net}/{num}"
payload = {"status": status}
result = threshold_request(url, payload)
return result
def get_irc_relays(net):
url = f"irc/network/{net}/relays"
payload = {}
relays = threshold_request(url, payload)
if not relays:
return {}
return relays
def get_irc_channels(net):
url = f"irc/network/{net}/channels"
payload = {}
channels = threshold_request(url, payload)
if not channels:
return {}
return channels
def part_channel(net, channel):
url = f"irc/network/{net}/channel"
payload = {"channel": channel}
parted = threshold_request(url, payload, method="DELETE")
if not parted:
return {}
return parted
def join_channel(net, channel):
url = f"irc/network/{net}/channel"
payload = {"channel": channel}
joined = threshold_request(url, payload, method="PUT")
if not joined:
return {}
return joined
def get_aliases():
url = "aliases"
payload = {}
aliases = threshold_request(url, payload, method="GET")
return aliases
def add_relay(net, num):
if num:
url = f"irc/network/{net}/{num}"
else:
url = f"irc/network/{net}"
payload = {}
created = threshold_request(url, payload, method="PUT")
return created
def del_relay(net, num):
url = f"irc/network/{net}/{num}"
payload = {}
deleted = threshold_request(url, payload, method="DELETE")
return deleted
def update_aliases(aliases):
url = "aliases"
payload = aliases
deleted = threshold_request(url, payload, method="POST")
return deleted
def run_auto(net):
url = f"irc/auto/{net}"
payload = {}
deleted = threshold_request(url, payload, method="POST")
return deleted
def run_list(net):
url = f"irc/list/{net}"
payload = {}
ran = threshold_request(url, payload, method="POST")
return ran
def create_network(data):
url = "irc/network/create"
payload = data
ran = threshold_request(url, payload, method="PUT")
return ran
def del_network(net):
url = f"irc/network/{net}"
payload = {}
deleted = threshold_request(url, payload, method="DELETE")
return deleted
def construct_alert_query():
# Get the initial query
query = {
"size": 25,
"query": {
"bool": {
"must": [
{"match": {"src": "irc"}},
]
}
},
"sort": [
{
"ts": {
"order": "desc",
}
}
],
}
return query
def send_irc_message(net, num, channel, msg, nick=None):
url = f"irc/msg/{net}/{num}"
payload = {"msg": msg, "channel": channel}
if nick:
payload["nick"] = nick
messaged = threshold_request(url, payload, method="PUT")
return messaged
def get_irc_nick(net, num):
url = f"irc/nick/{net}/{num}"
payload = {}
nick = threshold_request(url, payload, method="GET")
return nick
def get_irc_list_info(net):
url = f"irc/list/{net}"
payload = {}
listinfo = threshold_request(url, payload, method="GET")
return listinfo
def irc_get_unreg(net=None):
if net:
url = f"irc/reg/{net}"
else:
url = "irc/reg"
payload = {}
unreg = threshold_request(url, payload, method="GET")
return unreg
def irc_confirm_accounts(tokens):
url = "irc/reg"
payload = tokens
updated = threshold_request(url, payload, method="PUT")
return updated
def irc_provision_relay(net, num):
url = f"irc/network/{net}/{num}/provision"
payload = {}
provisioned = threshold_request(url, payload, method="POST")
return provisioned
def irc_enable_auth(net, num):
url = f"irc/network/{net}/{num}/auth"
payload = {}
enabled = threshold_request(url, payload, method="POST")
return enabled
def irc_check_auth(data):
url = "irc/auth"
payload = data
updated = threshold_request(url, payload, method="POST")
return updated
def get_irc_sinst(net):
url = f"irc/sinst/{net}"
payload = {}
authentity = threshold_request(url, payload, method="GET")
return authentity