Ping a Plex instance regularly, and send a message on a Discord channel if Plex instance is down
This program is a Discord bot. It checks regularly if a Plex instance is up and running, meaning:
- The Plex server is running
- Pinger can retrieve video list from each library ("Movies", "Series"...) specified in the configuration file
If the Plex instance is down, the bot will send a message on a Discord channel. You can optionally specify Discord user to ping in the message.
First of all you need to create a Discord bot, and invite it to a server with permissions to send messages and mention users.
To create a bot, visit Discord developer portal and create a new application.
Under the "Bot" tab, create a new bot and copy its token.
Then, under the "OAuth2" tab, section "URL Generator", select "bot" in the "Scopes" section, and select "Send messages" and "Mention everyone" in the "Bot permissions" section.
Copy the generated URL and paste it in your browser, or send it to the server owner. You will be prompted to select a server to invite the bot to. Select a server and click "Continue".
First, you need to activate developer mode in Discord. Go to "User Settings" > "Advanced" > "Developer Mode" and activate it.
Then, right-click on channel name you want the bot to send messages to, and select "Copy ID". This is the channel ID.
OPTIONAL: If you want to mention a user in the message, right-click on the user name and select "Copy ID". This is the user ID.
In order to ping your Plex instance, the bot needs Plex address and credentials.
Here is the location of the information you need:
(In the registry)
HKEY_CURRENT_USER\Software\Plex, Inc.\Plex Media Server
~/Library/Preferences/com.plexapp.plexmediaserver.plist
$PLEX_HOME/Library/Application Support/Plex Media Server/Preferences.xml
/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Preferences.xml
Retrieve the following information:
- PlexOnlineToken
- CertificateUUID
List the libraries you want to ping ("Movies", "Series"...).
Install the Rust toolchain from https://rustup.rs/.
git clone https://github.com/thomasarmel/plex_pinger.git
cd plex_pinger
cargo build --release
The binary is located in target/release/plex_pinger
. (.exe
on Windows)
Create the config.json file:
{
"plex": {
"domain": "[your plex instance domain]",
"ssl": [boolean, do you want to use SSL? (recommended)],
"port": [Plex default port, as integer. If you didn't change it, it should be 32400],
"plex_token": "[your PlexOnlineToken]",
"certificate_uuid": "[your CertificateUUID]",
"libraries": [
"Movies",
"Series"
] // <-- List the libraries you want to ping
},
"discord_bot": {
"bot_token": "[your Discord bot token]",
"msg_channel_id": [Discord channel ID where the bot will send messages, as integer],
"ping_user_id": [Optional: Discord user ID to ping, as integer]
},
"pinger_interval_seconds": [interval between each check ping, as integer],
"pinger_reminder_seconds": [interval between each reminder ping, as integer]
}
As there are secrets in the configuration file, Don't forget to set the correct permissions:
chmod 400 config.json
And finally run the program:
./target/release/plex_pinger config.json
If you prefer, you would rather turn the pinger into a service:
https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6