Implement API endpoint for network listing

This commit is contained in:
Mark Veidemanis 2022-07-25 18:05:53 +01:00
parent b149886128
commit 5aebf63c2e
3 changed files with 42 additions and 1 deletions

View File

@ -157,3 +157,36 @@ class API(object):
results = userinfo.getChanNum(net, data["query"]) results = userinfo.getChanNum(net, data["query"])
return dumps(results) return dumps(results)
@app.route("/irc/stats/", methods=["POST"])
@login_required
def irc_stats(self, request):
stats = {}
numChannels = 0
numWhoEntries = 0
for i in main.IRCPool.keys():
numChannels += len(main.IRCPool[i].channels)
numWhoEntries += userinfo.getNumTotalWhoEntries()
numRelays = 0
for net in main.network.keys():
numRelays += len(main.network[net].relays)
stats["servers_total_total"] = numRelays
stats["servers_total_unique"] = len(main.network.keys())
stats["servers_online_total"] = len(main.IRCPool.keys())
stats["servers_online_unique"] = len(main.liveNets())
stats["channels"] = numChannels
stats["records"] = numWhoEntries
stats["eventrate"] = main.lastMinuteSample
return dumps(stats)
@app.route("/irc/networks/", methods=["POST"])
@login_required
def irc_networks(self, request):
networks = {}
for net in main.network.keys():
networks[net] = {
"relays": len(main.network[net].relays),
"channels": userinfo.getTotalChanNum(net),
"records": userinfo.getNumWhoEntries(net),
}
return dumps(networks)

View File

@ -1,8 +1,8 @@
import main
from core.logstash import sendLogstashNotification from core.logstash import sendLogstashNotification
from core.relay import sendRelayNotification from core.relay import sendRelayNotification
from modules import userinfo from modules import userinfo
from utils.dedup import dedup from utils.dedup import dedup
import main
order = [ order = [
"type", "type",

View File

@ -38,6 +38,14 @@ def getChanList(name, nick):
return (i.decode() for i in result) return (i.decode() for i in result)
def getTotalChanNum(net):
"""
Get the number of channels a network has.
"""
chans = main.r.keys(f"live.who.{net}.*")
return len(chans)
def getUserNum(name, channels): def getUserNum(name, channels):
""" """
Get the number of users on a list of channels. Get the number of users on a list of channels.