Git Product home page Git Product logo

tronitor's Introduction

Tronitor

CodeFactor Travis (.com) branch made-with-bash GitHub Average time to resolve an issue Percentage of issues still open

A bash script to work with UptimeRobot, StatusCake, HealthChecks.io, and Upptime monitors via their respective APIs. It checks to make sure that the API key/token, username for StatusCake, and your GitHub username and the name of your Upptime repository on GitHub, that you provided are valid before performing any requested operations.

Contributors

GitHub contributors

Big thanks to nemchik for all the ideas and help with getting some things to work, and to 1activegeek for asking me to create this for him in the first place, albeit MUCH less complicated than what it's become.

Feel free to check out their work and buy them a beer too!

Application Healthchecks

This script partners up with my Application Healthchecks script that provides checks for a lot of popular HTPC applications, IE: Plex, Sonarr, Radarr, etc. that work with HealthChecks.io. Tronitor would allow you to pause and unpause the checks manually or on a schedule, via a cronjob, for planned maintenance, etc. This essentially allows you to create your own maintenance windows without having to pay for a premium account with either of the providers.

Package Requirements/Recommendations

cURL

The cURL command is required for the script to function as it's used to submit API calls to the providers. If it is not installed before you execute the script most, if not all, operations will fail. Because of this, the script does check whether or not cURL is installed and, if not, it will inform you as such and then exit.

JQ

The jq command is required for the script to function as it is used to more easily extract data from JSON files created by the script when gathering information for the monitoring providers and the corresponding checks/tests.

It is also used by the script to automatically format the JSON output into a human-readable and colorized output. There is a variable at the beginning of the script to set the use of the jq command (strictly for displaying the output of the script) to true or false. I've personally encountered some issues with it when using the script within a cronjob and not using jq to format the output resolves them. It is set to true by default.

# Set JQ to false to disable its use for displaying output.
# This works better for using the script with cronjobs, etc.
jq='true'

Installing JQ on Ubuntu Server 18.04:

tronyx@suladan:~$ sudo apt install jq
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  jq
0 upgraded, 1 newly installed, 0 to remove and 7 not upgraded.
Need to get 45.6 kB of archives.
After this operation, 90.1 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic/universe amd64 jq amd64 1.5+dfsg-2 [45.6 kB]
Fetched 45.6 kB in 0s (123 kB/s)
Selecting previously unselected package jq.
(Reading database ... 107503 files and directories currently installed.)
Preparing to unpack .../jq_1.5+dfsg-2_amd64.deb ...
Unpacking jq (1.5+dfsg-2) ...
Setting up jq (1.5+dfsg-2) ...
Processing triggers for man-db (2.8.3-2) ...

Sample output using JQ:

JQ True

Sample output without JQ:

JQ False

Setting it up

The best method to get the script working is to use git to clone the repository onto your preferred machine:

tronyx@suladan:~$ git clone https://github.com/tronyx/tronitor.git
Cloning into 'tronitor'...
remote: Enumerating objects: 108, done.
remote: Counting objects: 100% (108/108), done.
remote: Compressing objects: 100% (75/75), done.
remote: Total 262 (delta 60), reused 76 (delta 32), pack-reused 154
Receiving objects: 100% (262/262), 161.85 KiB | 6.74 MiB/s, done.
Resolving deltas: 100% (143/143), done.

⚠️ NOTE: You CAN get away with just grabbing a copy of the tronitor.sh script itself, but the monitor creation functionality will not work as it depends on the included template files in the repository.

The script stores the API keys/token, username for StatusCake, and, for Upptime, your GitHub username, PAT (Personal Access Token), and the name of your Upptime reposistory, for up to all four providers so that you do not need multiple copies of the script to work with each of the different providers.

If you do not know how to create a PAT for your GitHub account, you can checkout their documentation on it HERE.

The first time that you run the script for a specific monitor it will alert you that the API key/token, etc. are missing and prompt you to input them:

UptimeRobot

UptimeRobot User Data Prompt

StatusCake

StatusCake User Data Prompt

Healthchecks.io

Healthchecks User Data Prompt

⚠️ NOTE: If you are running your own, self-hosted version of the Healthchecks.io application, you will need to modify the healthchecksDomain variable on line 24 of the tronitor.sh script with the domain name that you're hosting the application with.

Upptime

Upptime/GitHub User Data Prompt

You can also simply open the script with your favorite text editor and add your provider's API key, if you're using StatusCake, your account username, and, if you're using Upptime, the repository owner (organization or user), your GitHub username, PAT (Personal Access Token), and the name of your Upptime reposistory.

After entering the information, the script will check whether or not it is valid and then add it to the script for you.

If you use the alert option, be sure to also enter in your Discord/Slack webhook URL. If you forget this as well, the script will also prompt you to enter it:

Webhook URL Prompt

Usage

Script Usage

The -m/--monitor option accepts both full and shorthand versions of the provider's name:

tronyx@suladan:~/tronitor$ ./tronitor.sh -m uptimerobot -l
tronyx@suladan:~/tronitor$ ./tronitor.sh -m ur -l
tronyx@suladan:~/tronitor$ ./tronitor.sh -m statuscake -l
tronyx@suladan:~/tronitor$ ./tronitor.sh -m sc -l
tronyx@suladan:~/tronitor$ ./tronitor.sh -m healthchecks -l
tronyx@suladan:~/tronitor$ ./tronitor.sh -m hc -l
tronyx@suladan:~/tronitor$ ./tronitor.sh -m upptime -l
tronyx@suladan:~/tronitor$ ./tronitor.sh -m up -l

Examples

Get account statistics

Display basic statistics for your account:

tronyx@suladan:~/tronitor$ ./tronitor.sh -m uptimerobot -s
Here are the basic statistics for your UptimeRobot account:

{
 "stat": "ok",
 "account": {
   "email": "[email protected]",
   "monitor_limit": 50,
   "monitor_interval": 5,
   "up_monitors": 14,
   "down_monitors": 0,
   "paused_monitors": 0
 }
}

List all monitors

Display all monitors associated with your account and their current statuses:

tronyx@suladan:~/tronitor$ ./tronitor.sh --monitor ur -l
The following UptimeRobot monitors were found in your UptimeRobot account:

Plex (ID: 779783111) - Status: Up
Radarr (ID: 780859973) - Status: Down
Sonarr (ID: 780859962) - Status: Paused
Tautulli (ID: 780859975) - Status: Seems down

Find currently paused monitors

Find and display all monitors in your account that are currently paused and then prompt you as to whether or not you would like to unpause them:

tronyx@suladan:~/tronitor$ ./tronitor.sh -m ur -f
The following StatusCake monitors are currently paused:

Plex (ID: 779783111)
Radarr (ID: 780859973)
Sonarr (ID: 780859962)
Tautulli (ID: 780859975)

Would you like to unpause the paused monitors? ([Y]es or [N]o):

You can also use the -n option to display the same list, but not display a prompt to unpause the paused monitors.

Discord alert for paused monitors

Using the -w option will check for any paused monitors and, if there are any, send an alert to the specified Discord/Slack webhook like below:

Discord/Slack Notification

If you set the notifyAll option to true, Tronitor will send a notification even if there are no paused monitors:

Discord/Slack Notification

Info

Display all information for a single monitor:

tronyx@suladan:~/tronitor$ ./tronitor.sh -m uptimerobot -i 'plex'
{
  "stat": "ok",
  "pagination": {
    "offset": 0,
    "limit": 50,
    "total": 1
  },
  "monitors": [
    {
      "id": 779783111,
      "friendly_name": "Plex",
      "url": "https://plex.tv",
      "type": 1,
      "sub_type": "",
      "keyword_type": null,
      "keyword_value": "",
      "http_username": "",
      "http_password": "",
      "port": "",
      "interval": 300,
      "status": 2,
      "create_datetime": 1513815865
    }
  ]
}

Get alert contacts

Displays a list of all of the alert contacts configured for the account:

tronyx@suladan:~/tronitor$ ./tronitor.sh -m ur -a
The following alert contacts have been found for your UptimeRobot account:

{
  "stat": "ok",
  "offset": 0,
  "limit": 50,
  "total": 2,
  "alert_contacts": [
    {
      "id": "0526944",
      "friendly_name": "E-Mail",
      "type": 2,
      "status": 2,
      "value": "[email protected]"
    },
    {
      "id": "2611518",
      "friendly_name": "Discord",
      "type": 11,
      "status": 2,
      "value": "https://discordapp.com/api/webhooks/123456789/qwerty-qwerty-qwerty/slack"
    }
  ]
}

This can be helpful when creating a new monitor as you can use the id field of the alert contact to specify the alert contact that you want to be notified when an event occurs with the new monitor that you're creating.

Pause all monitors

Pause all monitors in your account:

tronyx@suladan:~/tronitor$ ./tronitor.sh -m uptimerobot -p all
Pausing Plex:
{
  "stat": "ok",
  "monitor": {
    "id": 779783111
  }
}

Pausing Radarr:
{
  "stat": "ok",
  "monitor": {
    "id": 780859973
  }
}

Pausing Sonarr:
{
  "stat": "ok",
  "monitor": {
    "id": 780859962
  }
}

Pausing Tautulli:
{
  "stat": "ok",
  "monitor": {
    "id": 780859975
  }
}

⚠️ NOTE: Healthchecks.io works with cronjobs so, unless you disable your cronjobs for the HC.io monitors, or work with the created lock file, all paused monitors will become active again the next time they receive a ping. Tronitor creates a lock file, /tmp/tronitor/healthchecks.lock, so that you can modify your existing HC.io script to check for the lock file and not send pings if it is present.

Pause specific monitors

Pause specific monitors in your account:

tronyx@suladan:~/tronitor$ ./tronitor.sh --monitor ur -p 'Plex',780859973
Pausing Plex:
{
  "stat": "ok",
  "monitor": {
    "id": 779783111
  }
}

Pausing Radarr:
{
  "stat": "ok",
  "monitor": {
    "id": 780859973
  }
}

⚠️ NOTE: Healthchecks.io works with cronjobs so, unless you disable your cronjobs for the HC.io monitors, or work with the created lock file, all paused monitors will become active again the next time they receive a ping. Tronitor creates a lock file, /tmp/tronitor/MONITOR-UUID.lock, so that you can modify your existing HC.io script to check for the lock file and not send pings if it is present.

Unpause all currently paused monitors

Unpause all monitors in your account:

tronyx@suladan:~/tronitor$ ./tronitor.sh -m ur -u all
Unpausing Plex:
{
  "stat": "ok",
  "monitor": {
    "id": 779783111
  }
}

Unpausing Radarr:
{
  "stat": "ok",
  "monitor": {
    "id": 780859973
  }
}

Unpausing Sonarr:
{
  "stat": "ok",
  "monitor": {
    "id": 780859962
  }
}

Unpausing Tautulli:
{
  "stat": "ok",
  "monitor": {
    "id": 780859975
  }
}

Unpause specific monitors

Unpause specific monitors that are currently paused in your account:

tronyx@suladan:~/tronitor$ ./tronitor.sh -m ur -u 'Plex',780859973
Unpausing Plex:
{
  "stat": "ok",
  "monitor": {
    "id": 779783111
  }
}

Unpausing Radarr:
{
  "stat": "ok",
  "monitor": {
    "id": 780859973
  }
}

Create a new monitor

Monitors can be created using this option.

⚠️ NOTE: StatusCake's API is dumb and WILL let you create more tests than you're supposed to have with the limit for your account and it can cause some very odd behavior with the monitors.

Modify the settings of the corresponding monitor type template file in the corresponding Templates directory for your provider, IE: creating a new HTTP(s) monitor for UptimeRobot would require you to modify the Templates/UptimeRobot/new-http-monitor.json file. The full API documentation for the two providers can be found HERE (UR), HERE (SC), and HERE (HC) for information on monitor types and any required values and what they're for.

The following example is for creating a new HTTP(s) monitor for Google:

tronyx@suladan:~/tronitor$ cat Templates/UptimeRobot/new-http-monitor.json
{
      "api_key": "",
      "friendly_name": "Google",
      "url": "https://google.com",
      "type": 1,
      "http_username": "",
      "http_password": "",
      "interval": 300,
      "alert_contacts": "",
      "ignore_ssl_errors": "false",
      "format": "json"
}

The api_key field is filled in automatically by the script, but you can still add it yourself if you'd like to. The alert_contacts field can be filled in with the id field from your preferred alert contact which you can retrieve using the -a/--alerts option with the script.

Then just execute the script to create the monitor:

tronyx@suladan:~/tronitor$ ./tronitor.sh --monitor uptimerobot -c http
{
  "stat": "ok",
  "monitor": {
    "id": 781067574,
    "status": 1
  }
}

Resetting monitors

Reset (deleting all stats and response time data) all or specific monitors in your account:

tronyx@suladan:~/tronitor$ ./tronitor.sh -m ur -r google

***WARNING*** This will reset ALL data for the specified monitors!!!
Are you sure you wish to continue? ([Y]es or [N]o):
y

Resetting Google:
{
  "stat": "ok",
  "monitor": {
    "id": 781067574
  }
}

Deleting monitors

Delete all, or a specific, monitor from your account:

tronyx@suladan:~/tronitor$ ./tronitor.sh -m ur -d plex

***WARNING*** This will delete the specified monitor from your account!!!
Are you sure you wish to continue? ([Y]es or [N]o):
y

Deleting Plex:
{
  "stat": "ok",
  "monitor": {
    "id": 781067560
  }
}

tronitor's People

Contributors

1activegeek avatar nemchik avatar tronyx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tronitor's Issues

Creation of new Monitors for UR

Creation of new Monitors in UR does not work.
The reason for this is a wrongly defined Content Type in the curl POST operation for UR, so the JSON file is not processed correctly by UR:

Content-Type: application/x-www-form-urlencoded

To fix this issue, remove from line 1328 und 1330 in tronitor.sh the reference to this wrong Content-Type mentioned above.

btw: It would be great to create new Monitors without using a template file. Consider this as a feature request ;-)

Run tronitor as local user

Just wondering if it's possible? I haven't gone through the code deep enough to figure out why your require it aside from getting access to /tmp

Just about to create my first monitor from the command line! Liking it so far!

Calling script with >/dev/null fails with "(23) Failed writing body"

Describe the issue/bug
I trying to run the script from crontab. Calling script with >/dev/null fails with "(23) Failed writing body". My crontab:
0 2 * * * backup /opt/tronitor/tronitor.sh -m UptimeRobot -p 12345678,12345679 >/dev/null 2>&1

To Reproduce
Steps to reproduce the behavior:
./tronitor.sh -m UptimeRobot -p 12345678,12345679 >/dev/null

Expected behavior
Script should be able to run through and set all coma-seperated monitors to pause/unpause. I guess it's because the CURL-call. Another option would be to implement a "silent"-option

Actual behavior
Currently only the 1st monitor passed (12345678) will be paused

Uptimerobot API limit

Is your feature request related to a problem? Please describe.
I am running 5 monitors but as Uptimerobot introduced a API rate limit (10 per minute for the free edition) I run into the message "There seems to be an issue connecting to Uptimerobot. Please try again in a few minutes." every second run. So I did a trace and I saw that even a pause/unpause for 1 specific monitor will iterate (curl) through all monitors.

Describe the solution you'd like
Would it be possible to reduce the number of api (curl-) calls? Especially when only working with single monitor-id's?

Describe alternatives you've considered

Additional context

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.