Package: discord-system-observer-bot
A simple pythonDiscordbot that observes a local machine and sends notifications on resource exhaustion. It allows additionally to query the machine status via Discord.It registers the following command:dbot-observe- a blocking script, that runs periodic system checks and notifies about shortages
(may require extra dependencies to be installed for more information)RequirementsPython >= 3.6 (see badges above)discord.pypsutil(for cpu/ram/disk information querying)Extra:gpu:GPUtilplot: matplotlib, for generating plotsInstallationpython3-mpipinstalldiscord-system-observer-botOptionally, install it locally with--user.For GPU infos, you have to install extra dependencies:gpu(nvidia-smiinformation):python3-mpipinstalldiscord-system-observer-bot[gpu]ConfigurationConfiguration is done by placing a .dbot.conf file in one of the following directories:$HOME/.dbot.conf$HOME/dbot.conf./.dbot.conf./dbot.conf/etc/dbot.confAlternatively a configuration file can be provided via-c/--configCLI options.The configuration file should be a standard INI file. A template can be found in thetemplatesfolder. All configurations are placed under thediscord-botsection.Example:[discord-bot]# the bot token (used for login)token=abc# the numeric id of a channel, can be found when activating the developer options in appearanceschannel=123Usagedbot-observeis the main entry-point.Print help and available options:dbot-observe-hOutput:usage:dbot-observe[-h][-cCONFIG][-d][-nNAME]optionalarguments:-h,--helpshowthishelpmessageandexit-cCONFIG,--configCONFIGConfigfile-d,--debugEnabledebuglogging-nNAME,--nameNAMELocalmachinename(id)Starting the observer bot (without actually starting the background observation, just waiting for a Discord message to start/stop etc.):dbot-observeYou are always able to specify the configuration file like this:dbot-observe-c/path/to/dbot.conf[...]To display debugging information (api calls, log messages etc.):dbot-observe-d[...]You may also run the bot with the python module notation. But it will only run the same entry-point likedbot-observe.python-mdiscord_system_observer_bot[...]System Observer BotThedbot-observecommand runs a looping Discord task that checks every5 minsome predefined system conditions,
and sends a notification if abadnessvalue is over a threshold.
Thisbadnessvalue serves to either immediatly notify a channel if a system resource is exhausted or after some repeated limit exceedances.The code (checks and limits) can be found indiscord_system_observer_bot.sysinfo.
The current limits are some less-than educated guesses, and are subject to change.
Dynamic configuration is currently not an main issue, so users may need to clone the repo, change values and install the python package from source:gitclonehttps://github.com/Querela/discord-system-observer-bot.gitcddiscord-system-observer-bot/# [do the modifications in discord_system_observer_bot/sysinfo.py]python3-mpipinstall--user--upgrade--editable.[gpu,plot]The system information gathering may require the extra dependencies to be installed, likegpufor GPU information, orplotfor series charts.I suggest that you provide a different Discord channel for those notifications and create an extra.dbot-observer.confconfiguration file that can then be used like this:dbot-observe[-d]-c~/.dbot-observer.confEmbedded in other scriptsSending messages is rather straightforward.
More complex examples can be found in the CLI entrypoints, see filediscord_system_observer_bot.cli.
Below are some rather basic examples (extracted from the CLI code).Basic setup (logging + config loading):fromdiscord_system_observer_bot.cliimportsetup_logging,load_config# logging (rather basic, if needed)setup_logging(True)# load configuration file (provide filename or None)configs=load_config(filename=None)Sending a message:fromdiscord_system_observer_bot.botimportrun_observer# bot token and channel_id (loaded from configs or hard-coded)bot_token,channel_id=configs["token"],configs["channel"]# start the observer running (blocks forever)run_observer(bot_token,channel_id,message)Bot Creation etc.See information provided by:Tutorial for setting up a botDiscord developer application pageShort descriptionYou have to own a Discord server! Or know someone with administrator/moderation(?) privileges.Visit and login to theDiscord developer page.Create a new application. The given name is also the visible name of the bot. (default, can be changed later?)Create a bot (on theBotpage). You should disable thePublic Botoption.The bot login token (credentials) can be found on theBotpage.Change to theOAuth2page and checkScopes:BotBot Permissions:Send Messages,Attach Files(in theText Permissionscolumn)Copy the URL in theScopessection and paste it in a new browser tab.Now you can choose one (?) of yourownDiscord servers to add the bot to.(For this you need server administration permissions, or be the owner..?)To get the channel id, send the following message on your server\#channelname, or enable developer options.
You may want to visit the following pages for more information:discord.py bot help,Discord Help,reddit post.RelatedDiscord-Notifier-Bot,
a simple CLI tool to send notification messages or files to DiscordCopyright and License InformationCopyright (c) 2020 Erik Körner.  All rights reserved.See the file “LICENSE” for information on the history of this software, terms &
conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.All trademarks referenced herein are property of their respective holders.