axiacore / cachet-uptime-robot

Get data from UptimeRobot and send it to Cachet
MIT License
63 stars 22 forks source link

Setup Instructions #2

Closed brianjking closed 8 years ago

brianjking commented 8 years ago

Hi,

So excited to see you've made this, thank you! Can you please provide some assistance on getting this setup?

I'll either have the script on a separate Ubuntu system or possibly on my CentOS 6.8 cPanel system (dedicated server).

Thanks!

PabloVallejo commented 8 years ago

Hi @brianjking we've added some instructions to the README, take a look to them to setup the script in your server.

Best,

jbrooksuk commented 8 years ago

@PabloVallejo this is awesome! Are you on Twitter? I'd love to share from the Cachet account.

brianjking commented 8 years ago

@PabloVallejo -- Thanks, still a bit confused.

monitors_map = {
    'https://mydomain.com': {
        'api_key': 'cachet-api-key',
        'status_url': 'https://your-status-page-url.com',
        'component_id': 1,
        'metric_id': 1,
    }
}

Where do I insert the UptimeRobot API Key as your example only shows a space for the Cachet Key.

Secondly, when setting up the cronjob:

# Create a monitor instance 
m = Monitor()

# Gets uptime data from UptimeRobot and send to Cachet.
m.update_all_monitors()

Do I just need to do the following?

0 0 */2 * * /path/to/your/update_status.py

One last note -- since I'm calling to this via CRON doesn't it need to have a SHEBANG at the top of the update_status.py with the following?

#!/usr/bin/env python
PabloVallejo commented 8 years ago

@jbrooksuk thanks a lot, it'd be awesome, this is my twitter handle @PabloVallejo_

PabloVallejo commented 8 years ago

@brianjking we've updated the readmed in order to have the API Key info and also added the Shebang. Now your cron job should be working nicely.

On the other hand, this script is tested on Python 3, so you have to make sure it's installed in your machine.

Best,

brianjking commented 8 years ago

@PabloVallejo Should I be getting an error or anything if it's not working? I'm using Python 3 and have configured everything to match the README's details and nothing seems to be working, also no errors or anything are reported.

I can manually post from my local machine using the API docs on the Cachet site such as:

curl -H "Content-Type: application/json;" -H "X-Cachet-Token: REDACTED" -d '{"name":"API","description":"An example description","status":1}' http://monitor.dockdogs.com/api/v1/components

I can also use https://github.com/mtakaki/cachet-url-monitor, however, I'd really like to use the Uptime Robot integration.

PabloVallejo commented 8 years ago

Hi @brianjking we've added some messages showing what the script is doing. I recommend you run the script manually to make sure it's working and then create a cron job for it.

from update_status import Monitor

# Create a monitor instance 
m = Monitor()

# Gets uptime data from UptimeRobot and send to Cachet.
m.update_all_monitors()

>>> Updating monitor MyDomain: URL: https://mydomain.com - id: 12345678
>>> Created metric with id 27:
>>> {'data': {'id': 27, 'calculated_value': 7872, 'value': 328, 'updated_at': '2016-08-11 08:35:32', 'created_at': '2016-08-11 09:59:59', 'counter': 24, 'metric_id': 1}}
>>> ...

The configuration for your site should be the following.

MONITOR_LIST = {
    'http://dockdogs.com': {
        'api_key': 'cachet-api-key',
        'status_url': 'http://monitor.dockdogs.com/api/v1',
        'component_id': <id-of-your-component>,
        'metric_id': <id-of-the-uptime-metric>,
    }
}
brianjking commented 8 years ago

@PabloVallejo

root@ubuntu-512mb-nyc1-02:~/cachet-uptime-robot# python3 cron.py
Updating monitor dockdogs.com: URL: https://dockdogs.com/ - id: 775915061
Traceback (most recent call last):
  File "cron.py", line 6, in <module>
    m.update_all_monitors()
  File "/root/cachet-uptime-robot/update_status.py", line 242, in update_all_monitors
    self.send_data_to_catchet(monitor)
  File "/root/cachet-uptime-robot/update_status.py", line 191, in send_data_to_catchet
    website_config = MONITOR_LIST[monitor.get('url')]
KeyError: 'https://dockdogs.com/'
PabloVallejo commented 8 years ago

@brianjking each key of the MONITOR_LIST is the URL of the site your monitoring as seen in Uptime monitor. The error your getting is because the script is looking for the key https://dockdogs.com/ in MONITOR_LIST but the one in there is http://dockdogs.com.

Just change it to the following:

MONITOR_LIST = {
    'https://dockdogs.com/': {
        ...
    }
}
brianjking commented 8 years ago

@PabloVallejo

In MONITOR_LIST I've tried https://dockdogs.com, http://dockdogs.com, dockdogs.com, etc.

All generate this same error.

PabloVallejo commented 8 years ago

I see, have you tried with the slash at the end?

felipe3dfx commented 8 years ago

@brianjking Try adding '/' to end.

brianjking commented 8 years ago

With https or without?

PabloVallejo commented 8 years ago

Like this: https://dockdogs.com/

brianjking commented 8 years ago
root@ubuntu-512mb-nyc1-02:~/cachet-uptime-robot# python3 cron.py
Updating monitor dockdogs.com: URL: https://dockdogs.com/ - id: 775915061
Traceback (most recent call last):
  File "cron.py", line 6, in <module>
    m.update_all_monitors()
  File "/root/cachet-uptime-robot/update_status.py", line 242, in update_all_monitors
    self.send_data_to_catchet(monitor)
  File "/root/cachet-uptime-robot/update_status.py", line 204, in send_data_to_catchet
    website_config['metric_id']
  File "/root/cachet-uptime-robot/update_status.py", line 153, in get_last_metric_point
    response = request.urlopen(req)
  File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.5/urllib/request.py", line 472, in open
    response = meth(req, response)
  File "/usr/lib/python3.5/urllib/request.py", line 582, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib/python3.5/urllib/request.py", line 510, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 590, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found
PabloVallejo commented 8 years ago

Can you show me your MONITOR_LIST dict? just remove the api_key attribute

brianjking commented 8 years ago
# Each monitor must be an active UptimeRobot monitor and also
# there must be a Cachet metric and component for it.
MONITOR_LIST = {
    'https://dockdogs.com/': {
        'api_key': 'redacted',
        'status_url': 'http://health-dockdogs.rhcloud.com',
        'component_id': 1,
        'metric_id': 1,
    }
}

I've also done:

# Each monitor must be an active UptimeRobot monitor and also
# there must be a Cachet metric and component for it.
MONITOR_LIST = {
    'https://dockdogs.com/': {
        'api_key': 'redacted',
        'status_url': 'http://monitor.dockdogs.com',
        'component_id': 1,
        'metric_id': 1,
    }
}
screenshot8-11-1611 32
PabloVallejo commented 8 years ago

Status URL should be the URL of the API: http://monitor.dockdogs.com/api/v1

brianjking commented 8 years ago

@PabloVallejo Okay, thanks! I'm now seeing a metric chart being shown here: http://monitor.dockdogs.com/

Will this also update the status of component 1 if Uptime Robot reports issues reaching https://dockdogs.com?

screenshot8-11-1611 43
PabloVallejo commented 8 years ago

Great @brianjking!

Yes, it will also update the component you specified (id: 1).

This list represent how the statuses from UptimeRobot (left) are represented in cachet (right)

PabloVallejo commented 8 years ago

Hi @brianjking,

We've made a couple of improvements to the script so that it's easier to configure and run, also the graph is showing site availability instead of response time.

This is a working example: https://status.trabajoen.co/

jbrooksuk commented 8 years ago

Error 500 @PabloVallejo!

PabloVallejo commented 8 years ago

@jbrooksuk thanks a lot! we're investigating...

camilonova commented 8 years ago

@jbrooksuk I just ran php artisan app:install and it replaced my APP_KEY

By default it should not overwrite or set the APP_KEY if is already defined. Now it seems we've lost our installation. Is there something we can do?

jbrooksuk commented 8 years ago

Did you run php artisan app:install originally? Any changes after should be php artisan app:update.

camilonova commented 8 years ago

I didn't read that anywhere in the docs.

Having access to database is there something we can do to get our installation back?

camilonova commented 8 years ago

We're doing this because we are serving different installs from the same folder using this:

https://github.com/CachetHQ/Cachet/issues/236#issuecomment-91093152

@jbrooksuk How I can create another databases without damaging other installs?

jbrooksuk commented 8 years ago

That's not really supported behaviour, hence why it didn't work.

The app:update command is documented in the Upgrading docs. https://docs.cachethq.io/docs/updating-cachet#update-the-app

brianjking commented 8 years ago

@camilonova @PabloVallejo

Two things...

  1. How do I get it to show the availability? Should my metric configuration be "Average" or "Sum" in Cachet?
  2. When I run the command manually it seems to error out as it appears to want to access other sites in my Uptime Robot account.
root@ubuntu-512mb-nyc1-02:~/cachet-uptime# python3 update_status.py config.ini
Updating monitor dockdogs.com. URL: https://dockdogs.com/. ID: 775915061
Metric created: {'data': {'created_at': '2016-08-12 11:58:01', 'id': 961, 'metric_id': 1, 'calculated_value': 99.47, 'counter': 1, 'value': 99.47, 'updated_at': '2016-08-12 11:58:02'}}
Updating monitor BADASS Dash. URL: http://badassdash.com. ID: 775915065
ERROR: monitor is not valid

Note: My config.ini has the following:


[uptimeRobot]
UptimeRobotMainApiKey = redacted

[https://dockdogs.com/]
CachetApiKey = redacted
CachetUrl = http://monitor.dockdogs.com/
MetricId = 1
ComponentId = 1
camilonova commented 8 years ago

@brianjking sorry about that, please pull from master and try again.

brianjking commented 8 years ago

@camilonova This commit (https://github.com/Axiacore/cachet-uptime-robot/commit/db9f0648fe04c4bf7dc69515a21133bfd491b343) solves my monitor not found error.

However, I still have question 1 -- How do I get it to show the availability? Should my metric configuration be "Average" or "Sum" in Cachet? @jbrooksuk -- Was something added to do this in the 2.4 branch?

root@ubuntu-512mb-nyc1-02:~/cachet-uptime# python3 update_status.py config.ini
Updating monitor dockdogs.com. URL: https://dockdogs.com/. ID: 775915061
Metric created: {'data': {'metric_id': 1, 'calculated_value': 99.47, 'id': 962, 'value': 99.47, 'counter': 1, 'created_at': '2016-08-12 12:11:49', 'updated_at': '2016-08-12 12:11:49'}}
camilonova commented 8 years ago

This is how we set it: screen shot 2016-08-12 at 11 14 50 am

brianjking commented 8 years ago

If you set your Default Value in Cachet to be 100% how would it reduce this value?

python3 ~/cachet-uptime/update_status.py ~/cachet-uptime/config.ini
Updating monitor dockdogs.com. URL: https://dockdogs.com/. ID: 775915061
Metric created: {'data': {'updated_at': '2016-08-12 13:18:35', 'id': 965, 'value': 99.51, 'counter': 1, 'created_at': '2016-08-12 13:18:34', 'metric_id': 1, 'calculated_value': 99.51}}

For example - I'm getting a response back of 99.51%, however, my UptimeRobot is showing a value of 100% if I actually view it on the uptimerobot.com site.

camilonova commented 8 years ago

You're right. Actually we are getting this value from the API https://github.com/Axiacore/cachet-uptime-robot/blob/master/update_status.py#L199

Seems we need to change it. I'll take a look.

camilonova commented 8 years ago

Please pull again from master. It's now fixed.