mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-10 21:50:59 -05:00
Migrate Erordisplay to Logs
This commit is contained in:
parent
86ff8547bd
commit
00781aaa51
@ -1,84 +0,0 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
from sopel.cli import run
|
||||
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_recieved
|
||||
from sopel_modules.SpiceBot_SBTools import command_permissions_check
|
||||
|
||||
import spicemanip
|
||||
|
||||
import os
|
||||
|
||||
|
||||
@sopel.module.event('2005')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_startup_monologue_start(bot, trigger):
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
debuglines = errordisplay_fetch(bot)
|
||||
|
||||
# Check for python module errors during this startup
|
||||
searchphrasefound = []
|
||||
for line in debuglines:
|
||||
if "modules failed to load" in str(line) and "0 modules failed to load" not in str(line):
|
||||
searchphrase = str(line).replace(" modules failed to load", "")
|
||||
searchphrasefound.append(str(searchphrase) + " module(s) failed")
|
||||
elif "dict files failed to load" in str(line) and "0 dict files failed to load" not in str(line):
|
||||
searchphrase = str(line).replace(" dict files failed to load", "")
|
||||
searchphrasefound.append(str(searchphrase) + " dict file(s) failed")
|
||||
|
||||
if len(searchphrasefound):
|
||||
searchphrasefound.insert(0, "Notice to Bot Admins: ")
|
||||
searchphrasefound.append("Run the debug command for more information.")
|
||||
bot.osd(searchphrasefound, bot.channels.keys())
|
||||
|
||||
|
||||
@sopel.module.nickname_commands('debug')
|
||||
@sopel.module.thread(True)
|
||||
def bot_command_hub(bot, trigger):
|
||||
|
||||
if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
bot.say("I was unable to process this Bot Nick command due to privilege issues.")
|
||||
return
|
||||
|
||||
bot.osd("Is Examining systemd Log(s).", trigger.sender, 'ACTION')
|
||||
|
||||
debuglines = errordisplay_fetch(bot)
|
||||
|
||||
if len(debuglines) == 0:
|
||||
bot.osd("had no log(s) for some reason", trigger.sender, 'ACTION')
|
||||
return
|
||||
|
||||
for line in debuglines:
|
||||
bot.osd(line)
|
||||
|
||||
|
||||
def errordisplay_fetch(bot):
|
||||
# servicepid = str(os.popen("systemctl show " + str(bot.nick) + " --property=MainPID").read()).split("=")[-1]
|
||||
servicepid = get_running_pid(bot)
|
||||
debuglines = []
|
||||
for line in os.popen(str("sudo journalctl _PID=" + str(servicepid))).read().split('\n'):
|
||||
if not str(line).startswith("-- Logs begin at"):
|
||||
line = str(line).split(str(os.uname()[1] + " "))[-1]
|
||||
if not str(line).startswith("sudo"):
|
||||
lineparts = str(line).split(": ")
|
||||
del lineparts[0]
|
||||
line = spicemanip.main(lineparts, 0)
|
||||
debuglines.append(str(line))
|
||||
else:
|
||||
debuglines.append(str(line))
|
||||
return debuglines
|
||||
|
||||
|
||||
def get_running_pid(bot):
|
||||
try:
|
||||
filename = "/run/sopel/" + str(bot.nick) + ".pid"
|
||||
with open(filename, 'r') as pid_file:
|
||||
pidnum = int(pid_file.read())
|
||||
except Exception as e:
|
||||
pidnum = e
|
||||
pidnum = str(os.popen("systemctl show " + str(bot.nick) + " --property=MainPID").read()).split("=")[-1]
|
||||
return pidnum
|
||||
@ -1,12 +0,0 @@
|
||||
# coding=utf8
|
||||
"""Sopel Startup Monologue
|
||||
|
||||
Sopel Startup Monologue displays to all channels that the bot is online
|
||||
"""
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
from .ErrorDisplay import *
|
||||
|
||||
__author__ = 'Sam Zick'
|
||||
__email__ = 'sam@deathbybandaid.net'
|
||||
__version__ = '0.1.1'
|
||||
30
sopel_modules/SpiceBot_Logs/ErrorDisplay.py
Normal file
30
sopel_modules/SpiceBot_Logs/ErrorDisplay.py
Normal file
@ -0,0 +1,30 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_recieved
|
||||
from .Logs import errordisplay_fetch
|
||||
|
||||
|
||||
@sopel.module.event('2005')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_startup_monologue_start(bot, trigger):
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
debuglines = errordisplay_fetch(bot)
|
||||
|
||||
searchphrasefound = []
|
||||
for line in debuglines:
|
||||
if "modules failed to load" in str(line) and "0 modules failed to load" not in str(line):
|
||||
searchphrase = str(line).replace(" modules failed to load", "")
|
||||
searchphrasefound.append(str(searchphrase) + " module(s) failed")
|
||||
elif "dict files failed to load" in str(line) and "0 dict files failed to load" not in str(line):
|
||||
searchphrase = str(line).replace(" dict files failed to load", "")
|
||||
searchphrasefound.append(str(searchphrase) + " dict file(s) failed")
|
||||
|
||||
if len(searchphrasefound):
|
||||
searchphrasefound.insert(0, "Notice to Bot Admins: ")
|
||||
searchphrasefound.append("Run the debug command for more information.")
|
||||
bot.osd(searchphrasefound, bot.channels.keys())
|
||||
@ -8,6 +8,10 @@ from sopel.config.types import StaticSection, ValidatedAttribute
|
||||
from sopel_modules.SpiceBot_SBTools import bot_logging
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger
|
||||
|
||||
import os
|
||||
|
||||
import spicemanip
|
||||
|
||||
|
||||
def configure(config):
|
||||
config.define_section("SpiceBot_Logs", SpiceBot_Logs_MainSection, validate=False)
|
||||
@ -31,7 +35,7 @@ def setup(bot):
|
||||
|
||||
def bot_logs_setup_check(bot):
|
||||
if 'SpiceBot_Logs' not in bot.memory:
|
||||
bot.memory['SpiceBot_Logs'] = {"logs": {}, "queue": []}
|
||||
bot.memory['SpiceBot_Logs'] = {"logs": {"Sopel_systemd": []}, "queue": []}
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
@ -62,6 +66,33 @@ def join_log_channel(bot, trigger):
|
||||
return
|
||||
|
||||
|
||||
def errordisplay_fetch(bot):
|
||||
servicepid = get_running_pid(bot)
|
||||
debuglines = []
|
||||
for line in os.popen(str("sudo journalctl _PID=" + str(servicepid))).read().split('\n'):
|
||||
if not str(line).startswith("-- Logs begin at"):
|
||||
line = str(line).split(str(os.uname()[1] + " "))[-1]
|
||||
if not str(line).startswith("sudo"):
|
||||
lineparts = str(line).split(": ")
|
||||
del lineparts[0]
|
||||
line = spicemanip.main(lineparts, 0)
|
||||
debuglines.append(str(line))
|
||||
else:
|
||||
debuglines.append(str(line))
|
||||
return debuglines
|
||||
|
||||
|
||||
def get_running_pid(bot):
|
||||
try:
|
||||
filename = "/run/sopel/" + str(bot.nick) + ".pid"
|
||||
with open(filename, 'r') as pid_file:
|
||||
pidnum = int(pid_file.read())
|
||||
except Exception as e:
|
||||
pidnum = e
|
||||
pidnum = str(os.popen("systemctl show " + str(bot.nick) + " --property=MainPID").read()).split("=")[-1]
|
||||
return pidnum
|
||||
|
||||
|
||||
@sopel.module.event('2004')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_setup(bot, trigger):
|
||||
|
||||
@ -8,15 +8,16 @@ import spicemanip
|
||||
|
||||
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_check
|
||||
from .Logs import errordisplay_fetch
|
||||
|
||||
|
||||
@sopel.module.nickname_commands('logs')
|
||||
@sopel.module.nickname_commands('logs', 'debug')
|
||||
def bot_command_action(bot, trigger):
|
||||
|
||||
while not bot_events_check(bot, '2004'):
|
||||
pass
|
||||
|
||||
if not command_permissions_check(bot, trigger, ['admins', 'owner']):
|
||||
if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
bot.say("I was unable to process this Bot Nick command due to privilege issues.")
|
||||
return
|
||||
|
||||
@ -29,10 +30,15 @@ def bot_command_action(bot, trigger):
|
||||
|
||||
logtype = inlist_match(bot, logtype, bot.memory['SpiceBot_Logs'].keys())
|
||||
|
||||
if len(bot.memory['SpiceBot_Logs']["logs"][logtype]) == 0:
|
||||
if logtype != "Sopel_systemd":
|
||||
logindex = bot.memory['SpiceBot_Logs']["logs"][logtype]
|
||||
else:
|
||||
logindex = errordisplay_fetch(bot)
|
||||
|
||||
if not len(logindex):
|
||||
bot.osd("No logs found for " + str(logtype) + ".")
|
||||
return
|
||||
|
||||
bot.osd("Is Examining " + str(logtype) + " log(s).")
|
||||
for line in bot.memory['SpiceBot_Logs']["logs"][logtype]:
|
||||
for line in logindex:
|
||||
bot.osd(" " + str(line))
|
||||
|
||||
@ -3,6 +3,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
|
||||
|
||||
from .Logs import *
|
||||
from .Logs_Command import *
|
||||
from .ErrorDisplay import *
|
||||
|
||||
__author__ = 'Sam Zick'
|
||||
__email__ = 'sam@deathbybandaid.net'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user