Code Monkey home page Code Monkey logo

cachet-url-monitor's Introduction

Status

CircleCI Coverage Status Codacy Badge Docker Pulls Docker stars License Latest release pre-commit

cachet-url-monitor

Python plugin for cachet that monitors an URL, verifying it's response status and latency. The frequency the URL is tested is configurable, along with the assertion applied to the request response.

This project is available at PyPI: https://pypi.python.org/pypi/cachet-url-monitor

Configuration

endpoints:
  - name: Google
    url: http://www.google.com
    method: GET
    header:
      SOME-HEADER: SOME-VALUE
    timeout: 1 # seconds
    expectation:
      - type: HTTP_STATUS
        status_range: 200-205
      - type: LATENCY
        threshold: 1
      - type: REGEX
        regex: ".*<body>.*"
    allowed_fails: 0
    component_id: 1
    metric_id: 1
    action:
      - UPDATE_STATUS
    public_incidents: true
    latency_unit: ms
    frequency: 5
  - name: Amazon
    url: http://www.amazon.com
    method: GET
    header:
      SOME-HEADER: SOME-VALUE
    timeout: 1 # seconds
    expectation:
      - type: HTTP_STATUS
        status_range: 200-205
        incident: MAJOR
      - type: LATENCY
        threshold: 1
      - type: REGEX
        regex: ".*<body>.*"
        threshold: 10
    allowed_fails: 0
    component_id: 2
    action:
      - CREATE_INCIDENT
    public_incidents: true
    latency_unit: ms
    frequency: 5
  - name: Insecure-site
    url: https://www.Insecure-site-internal.com
    method: GET
    header:
      SOME-HEADER: SOME-VALUE
    insecure: true
    timeout: 1 # seconds
    expectation:
      - type: HTTP_STATUS
        status_range: 200-205
    allowed_fails: 0
    component_id: 2
    action:
      - CREATE_INCIDENT
    public_incidents: true
    frequency: 5
cachet:
  api_url: http://status.cachethq.io/api/v1
  token:
    - type: ENVIRONMENT_VARIABLE
      value: CACHET_TOKEN
    - type: AWS_SECRETS_MANAGER
      secret_name: cachethq
      secret_key: token
      region: us-west-2
    - type: TOKEN
      value: my_token
webhooks:
  - url: "https://push.example.com/message?token=<apptoken>"
    params:
      title: "{title}"
      message: "{message}"
      priority: 5
messages:
  incident_outage: "{name} is unavailable"
  incident_operational: "{name} is operational"
  incident_performance: "{name} has degraded performance"
  • endpoints, the configuration about the URL/Urls that will be monitored.
    • name, The name of the component. This is now mandatory (since 0.6.0) so we can distinguish the logs for each URL being monitored.
    • url, the URL that is going to be monitored. mandatory
    • method, the HTTP method that will be used by the monitor. mandatory
    • header, client header passed to the request. Remove if you do not want to pass a header.
    • insecure, for URLs which have self-singed/invalid SSL certs OR you wish to disable SSL check, use this key. Default is false, so by default we validate SSL certs.
    • timeout, how long we'll wait to consider the request failed. The unit of it is seconds. mandatory
    • expectation, the list of expectations set for the URL. mandatory
      • HTTP_STATUS, we will verify if the response status code falls into the expected range. Please keep in mind the range is inclusive on the first number and exclusive on the second number. If just one value is specified, it will default to only the given value, for example 200 will be converted to 200-201.
      • LATENCY, we measure how long the request took to get a response and fail if it's above the threshold . The unit is in seconds.
      • REGEX, we verify if the response body matches the given regex.
    • allowed_fails, create incident/update component status only after specified amount of failed connection trials.
    • component_id, the id of the component we're monitoring. This will be used to update the status of the component. mandatory
    • metric_id, this will be used to store the latency of the API. If this is not set, it will be ignored.
    • action, the action to be done when one of the expectations fails. This is optional and if left blank , nothing will be done to the component.
      • CREATE_INCIDENT, we will create an incident when the expectation fails.
      • UPDATE_STATUS, updates the component status.
      • PUSH_METRICS, uploads response latency metrics.
    • public_incidents, boolean to decide if created incidents should be visible to everyone or only to logged in users. Important only if CREATE_INCIDENT or UPDATE_STATUS are set.
    • latency_unit, the latency unit used when reporting the metrics. It will automatically convert to the specified unit. It's not mandatory and it will default to seconds. Available units: ms, s, m, h.
    • frequency, how often we'll send a request to the given URL. The unit is in seconds.
  • cachet, this is the settings for our cachet server.
    • api_url, the cachet API endpoint. mandatory
    • token, the API token. It can either be a string (backwards compatible with old configuration) or a list of token providers. It will read in the specified order and fallback to the next option if no token could be found . (since 0.6.10) mandatory
      • ENVIRONMENT_VARIABLE, it will read the token from the specified environment variable.
      • TOKEN, it's a string and it will be read directly from the configuration.
      • AWS_SECRETS_MANAGER, it will attempt reading the token from AWS Secrets Manager. It requires setting up the AWS credentials into the docker container. More instructions below. It takes these parameters:
        • secret_name, the name of the secret.
        • secret_key, the key under which the token is stored.
        • region, the AWS region.
  • webhooks, generic webhooks to be notified about incident updates
    • url, webhook URL, will be interpolated
    • params, POST parameters, will be interpolated
  • messages, customize text for generated events, use any of endpoint parameter in interpolation
    • incident_outage, title of incident in case of outage
    • incident_performace, title of incident in case of performance issues
    • incident_operational, title of incident in case service is operational

Each expectation has their own default incident status. It can be overridden by setting the incident property to any of the following values:

  • PARTIAL
  • MAJOR
  • PERFORMANCE

By choosing any of the aforementioned statuses, it will let you control the kind of incident it should be considered . These are the default incident status for each expectation type:

Expectation Incident status
HTTP_STATUS PARTIAL
LATENCY PERFORMANCE
REGEX PARTIAL

Following parameters are available in webhook interpolation

Parameter Description
{title} Event title, includes endpoint name and short status
{message} Event message, same as sent to Cachet

AWS Secrets Manager

This tools can integrate with AWS Secrets Manager, where the token is fetched directly from the service. In order to get this functionality working, you will need to setup the AWS credentials into the container. The easiest way would be setting the environment variables:

$ docker run --rm -it -e AWS_ACCESS_KEY_ID=xyz -e AWS_SECRET_ACCESS_KEY=aaa -v "$PWD"/my_config.yml:/usr/src/app/config/config.yml:ro mtakaki/cachet-url-monitor

Setting up

The application should be installed using virtualenv, through the following command:

$ git clone https://github.com/mtakaki/cachet-url-monitor.git
$ cd cachet-url-monitor
$ virtualenv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
$ python3 setup.py install

To start the agent:

$ python3 cachet_url_monitor/scheduler.py config.yml

Docker

You can run the agent in docker, so you won't need to worry about installing python, virtualenv, or any other dependency into your OS. The Dockerfile is already checked in and it's ready to be used.

You have two choices, checking this repo out and building the docker image or it can be pulled directly from dockerhub. You will need to create your own custom config .yml file and run (it will pull latest):

$ docker pull mtakaki/cachet-url-monitor
$ docker run --rm -it -v "$PWD":/usr/src/app/config/ mtakaki/cachet-url-monitor

If you're going to use a file with a name other than config.yml, you will need to map the local file, like this:

$ docker run --rm -it -v "$PWD"/my_config.yml:/usr/src/app/config/config.yml:ro mtakaki/cachet-url-monitor

Docker compose

Docker compose has been removed from this repo as it had a dependency on PostgreSQL and it slightly complicated how it works. This has been kindly handled on: https://github.com/boonisz/cachet-url-monitor-dc It facilitates spawning CachetHQ with its dependencies and cachet-url-monitor alongside to it.

Generating configuration from existing CachetHQ instance (since 0.6.2)

In order to expedite the creation of your configuration file, you can use the client to automatically scrape the CachetHQ instance and spit out a YAML file. It can be used like this:

$ python cachet_url_monitor/client.py http://localhost/api/v1 my-token test.yml

Or from docker (you will end up with a test.yml in your $PWD/tmp folder):

$ docker run --rm -it -v $PWD/tmp:/home/tmp/ mtakaki/cachet-url-monitor python3.7 ./cachet_url_monitor/client.py http://localhost/api/v1 my-token /home/tmp/test.yml

The arguments are:

  • URL, the CachetHQ API URL, so that means appending /api/v1 to your hostname.
  • token, the token that has access to your CachetHQ instance.
  • filename, the file where it should write the configuration.

Caveats

Because we can't predict what expectations will be needed, it will default to these behavior:

  • Verify a [200-300[ HTTP status range.
  • If status fail, make the incident major and public.
  • Frequency of 30 seconds.
  • GET request.
  • Timeout of 1s.
  • We'll read the link field from the components and use it as the URL.

Troubleshooting

SSLERROR

If it's throwing the following exception:

raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='redacted', port=443): Max retries exceeded with url: /api/v1/components/19 (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)'),))

It can be resolved by setting the CA bundle environment variable REQUESTS_CA_BUNDLE pointing at your certificate file. It can either be set in your python environment, before running this tool, or in your docker container.

Development

If you want to contribute to this project, feel free to fork this repo and post PRs with any improvements or bug fixes. This is highly appreciated, as it's been hard to deal with numerous requests coming my end.

This repo is setup with pre-commit hooks and it should ensure code style is consistent . The steps to start development on this repo is the same as the setup aforementioned above:

$ git clone https://github.com/mtakaki/cachet-url-monitor.git
$ cd cachet-url-monitor
$ pre-commit install
$ virtualenv venv
$ source venv/bin/activate
$ tox

cachet-url-monitor's People

Contributors

chris-str-cst avatar dependabot[bot] avatar dgiebert avatar jacekszubert avatar kaeltis avatar mazhead avatar mtakaki avatar nijel avatar rahulg963 avatar waffle-iron 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  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  avatar  avatar  avatar  avatar  avatar

cachet-url-monitor's Issues

Monitor uses UTC

Hi!

I've setup the monitor so it measures latency and everything works as a charm, however! I've tried setting the timezone on my ubuntu server with sudo dpkg-reconfigure tzdata

But Cachet still reports the latency reports an hour earlier than it should be.

I am currently using the Docker image, when running the monitor.

Monitor Appliance

Hello

I use "cachet" with "cachet-url-monitor" just perfect :)

I would like to know if it is possible to ping a server or appilance (switch, firewall ...)

Is there a free solution or module;)

Thank you

Error :(

(cachet-url-monitor)root@244637a1:/opt/cachet-url-monitor# python cachet_url_monitor/scheduler.py config.yml
     INFO [2017-03-14 18:03:29,590] cachet_url_monitor.configuration.Configuration - Current configuration:
cachet:
  action:
  - CREATE_INCIDENT
  - UPDATE_STATUS
  api_url: https://status.PAGE.eu/api/v1
  component_id: 3
  public_incidents: true
endpoint:
  expectation:
  - status: 200
    type: HTTP_STATUS
  - threshold: 1
    type: LATENCY
  - regex: .*(<body).*
    type: REGEX
  method: GET
  timeout: 1
  url: https://PAGE.eu
frequency: 30

Traceback (most recent call last):
  File "cachet_url_monitor/scheduler.py", line 89, in <module>
    scheduler = Scheduler(sys.argv[1])
  File "cachet_url_monitor/scheduler.py", line 55, in __init__
    self.configuration = Configuration(config_file)
  File "/opt/cachet-url-monitor/cachet_url_monitor/configuration.py", line 91, in __init__
    self.default_metric_value = self.get_default_metric_value()
  File "/opt/cachet-url-monitor/cachet_url_monitor/configuration.py", line 107, in get_default_metric_value
    return get_metric_request.json()['data']['default_value']
KeyError: 'data'
(cachet-url-monitor)root@244637a1:/opt/cachet-url-monitor# 

Release-0.6.4 doesn't load config file anymore

cachet-monitor_1  | Traceback (most recent call last):
cachet-monitor_1  |   File "./cachet_url_monitor/scheduler.py", line 144, in <module>
cachet-monitor_1  |     token = os.environ.get('CACHET_TOKEN') or config_data['cachet']['token']
cachet-monitor_1  | NameError: name 'os' is not defined
cachet-monitor:
    # https://github.com/mtakaki/cachet-url-monitor/blob/master/config.yml
    image: mtakaki/cachet-url-monitor:release-0.6.4
    volumes: 
      - "${PWD}/config.yml:/usr/src/app/config/config.yml:ro"

It works with release-0.6.3

Pushing latency as milliseconds

Usually status pages show the latency in ms.

Cachet can't convert the seconds to milliseconds, so url-monitor should be able to do that.

I'm suggesting a config param to switch to ms.

SSLError

getting this error when trying to start url monitor, any ideas?

Traceback (most recent call last):
File "cachet_url_monitor/scheduler.py", line 90, in
scheduler = Scheduler(sys.argv[1])
File "cachet_url_monitor/scheduler.py", line 56, in init
self.configuration = Configuration(config_file)
File "/root/cachet-url-monitor/cachet_url_monitor/configuration.py", line 113, in init
self.status = get_current_status(self.api_url, self.component_id, self.headers)
File "/root/cachet-url-monitor/cachet_url_monitor/configuration.py", line 59, in get_current_status
get_status_request = requests.get('%s/components/%s' % (endpoint_url, component_id), headers=headers)
File "/root/cachet-url-monitor/lib/python2.7/site-packages/requests/api.py", line 72, in get
return request('get', url, params=params, **kwargs)
File "/root/cachet-url-monitor/lib/python2.7/site-packages/requests/api.py", line 58, in request
return session.request(method=method, url=url, **kwargs)
File "/root/cachet-url-monitor/lib/python2.7/site-packages/requests/sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "/root/cachet-url-monitor/lib/python2.7/site-packages/requests/sessions.py", line 640, in send
history = [resp for resp in gen] if allow_redirects else []
File "/root/cachet-url-monitor/lib/python2.7/site-packages/requests/sessions.py", line 218, in resolve_redirects
**adapter_kwargs
File "/root/cachet-url-monitor/lib/python2.7/site-packages/requests/sessions.py", line 618, in send
r = adapter.send(request, **kwargs)
File "/root/cachet-url-monitor/lib/python2.7/site-packages/requests/adapters.py", line 506, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='itstatus.redacted.com', port=443): Max retries exceeded with url: /api/v1/components/19 (Caused by SSLError(SSLError(1, u'[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:579)'),))

The cert is fine, it's our wildcard.

Thanks

Metrics not pushed

Hi @mtakaki,

First of all, thanks for this great piece of code.

I'm a pretty new user of cachet and cachet-url-monitor. So far, I have managed to configure the different components and the status is updated correctly. My problem is that I cannot see any metrics pushed but I cannot see what I am doing wrong.

I am running cachet-url-monitor in the provided Docker Container.

Here is my config:

endpoints:
  - name: _NAME_
    url: https://_URL_TO_MONITOR_/
    method: GET
    timeout: 1 # seconds
    expectation:
      - type: HTTP_STATUS
        status_range: 200
      - type: LATENCY
        threshold: 1 # seconds
      - type: REGEX
        regex: ".*<body>.*"
    allowed_fails: 0
    component_id: 25
    metric_id: 25
    action:
      - UPDATE_STATUS
      - PUSH_METRICS
    public_incidents: true
    latency_unit: ms
    frequency: 60 # seconds
cachet:
  api_url: https://_MY_CACHET_INSTANCE_/api/v1
  token: _TOKEN_

An extract of the log (seems to me that I should have some "Metric uploaded" logs between the "No changes")

     INFO [2020-03-22 13:46:03,296] cachet_url_monitor.configuration.Configuration._NAME_ - Current configuration:
cachet:
  api_url: https://_MY_CACHET_INSTANCE_/api/v1
endpoints:
  action:
  - UPDATE_STATUS
  - PUSH_METRICS
  allowed_fails: 0
  component_id: 25
  expectation:
  - status_range: 200
    type: HTTP_STATUS
  - threshold: 1
    type: LATENCY
  - regex: .*<body>.*
    type: REGEX
  frequency: 60
  latency_unit: ms
  method: GET
  metric_id: 25
  name: _NAME_
  public_incidents: true
  timeout: 1
  url: https://_URL_TO_MONITOR_/

     INFO [2020-03-22 13:46:03,491] cachet_url_monitor.configuration.Configuration._NAME_ - Component current status: ComponentStatus.OPERATIONAL
     INFO [2020-03-22 13:46:03,491] cachet_url_monitor.configuration.Configuration._NAME_ - Monitoring URL: GET https://_URL_TO_MONITOR_/
     INFO [2020-03-22 13:46:03,491] cachet_url_monitor.configuration.Configuration._NAME_ - Registered expectation: 'HTTP status range: [200, 201['
     INFO [2020-03-22 13:46:03,492] cachet_url_monitor.configuration.Configuration._NAME_ - Registered expectation: 'Latency threshold: 1.0000 seconds'
     INFO [2020-03-22 13:46:03,492] cachet_url_monitor.configuration.Configuration._NAME_ - Registered expectation: 'Regex: .*<body>.*'
     INFO [2020-03-22 13:46:03,492] cachet_url_monitor.scheduler - Registering action UPDATE_STATUS
     INFO [2020-03-22 13:46:03,492] cachet_url_monitor.scheduler - Registering action PUSH_METRICS
     INFO [2020-03-22 13:46:03,492] cachet_url_monitor.scheduler.Scheduler - Starting monitor agent...
     INFO [2020-03-22 13:47:03,666] cachet_url_monitor.configuration.Configuration._NAME_ - No changes to component status.
     INFO [2020-03-22 13:48:03,795] cachet_url_monitor.configuration.Configuration._NAME_ - No changes to component status.
     INFO [2020-03-22 13:49:03,936] cachet_url_monitor.configuration.Configuration._NAME_ - No changes to component status.
     INFO [2020-03-22 13:50:04,058] cachet_url_monitor.configuration.Configuration._NAME_ - No changes to component status.

I configured the metric in Cachet like so:

  • Suffix: ms
  • Calculation of metrics: Average
  • Default value: 0
  • Decimal Places: 0
  • How many minutes of threshold between metric points: 1
  • Display chart on status page: Yes

And nothing is visible on the dashbord and there is no metrics_points in cachet database (not access logs on metrics endpoints in cachet).

I have tried to tweak the monitored url and managed to get a status change by HTTP_STATUS and LATENCY, neither seems to trigger a metric push.

Any insight will be greatly appreciated.

Thanks,

Self-Signed certificate

Hi getting this error
requests.exceptions.SSLError: HTTPSConnectionPool(host='cachetdocker_cachet_1', port=8000): Max retries exceeded with url: /api/v1/components/1 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1056)')))

Could it be avoided by doing the REQUEST variable?
Thanks
Math

No module named 'cachet_url_monitor'

Hi, I've followed instructions from the readme.md but got stuck and failed to launch it due to the following error.

Traceback (most recent call last):
  File "cachet_url_monitor/scheduler.py", line 8, in <module>
    from cachet_url_monitor.configuration import Configuration
ImportError: No module named 'cachet_url_monitor'

From my understanding it looks like it's not able to import itself. All pip requirements are already installed so I have no idea why this is occuring. I am running on a Fedora 27 CE server (no docker) if that helps.

URL unavailable

Hey,i always become this error:

URL unavailable
INFO [2019-07-11 17:04:03,217] cachet_url_monitor.configuration.Configuration - Monitoring URL: GET https://example.de/ INFO [2019-07-11 17:04:03,217] cachet_url_monitor.configuration.Configuration - Registered expectation: 'HTTP status range: (200, 300)' INFO [2019-07-11 17:04:03,217] cachet_url_monitor.scheduler.Scheduler - Registering action CREATE_INCIDENT INFO [2019-07-11 17:04:03,217] cachet_url_monitor.scheduler.Scheduler - Registering action UPDATE_STATUS INFO [2019-07-11 17:04:03,217] cachet_url_monitor.scheduler.Scheduler - Starting monitor agent... WARNING [2019-07-11 17:04:33,245] cachet_url_monitor.configuration.Configuration - Request timed out INFO [2019-07-11 17:04:33,245] cachet_url_monitor.configuration.Configuration - Failure #1 with threshold set to 0 INFO [2019-07-11 17:04:33,380] cachet_url_monitor.configuration.Configuration - Incident uploaded, API unhealthy: component status [2], message: "Request timed out"

My config is:

endpoint: url: https://example.de/ method: GET #header: #SOME-HEADER: SOME-VALUE timeout: 0.01 expectation: - type: HTTP_STATUS status_range: 200-300 #- type: LATENCY # threshold: 15 #- type: REGEX # regex: '.*(<body).*' allowed_fails: 0 cachet: api_url: https://status.example.de/api/v1 token: my_token component_id: 1 metric_id: 1 action: - CREATE_INCIDENT - UPDATE_STATUS public_incidents: true latency_unit: s frequency: 30

Edited url to example.de, dont post my real url here, also my token ;)

So what i am do wrong?

Monitoring executed several times

I have configured monitor to monitor 11 services and I've noticed that some of them are triggered several times. Looking at the scheduler module, it doesn't seem to be designed with multiple threads in mind. When triggering it from thread, it can easily happen that more threads get the same pending tasks.

Possible solutions:

  • Use just one scheduler thread, let it execute the tasks in separate threads.
  • Use per thread scheduler instance.

IsADirectoryError: [Errno 21] Is a directory: 'config/config.yml'

Hello,

Sorry but i may sounds weird because i am bit confused on how to run with docker.
I first pull the image from the docker hub and then i get an erroor with this command:

docker run --rm -it -v "$PWD":/usr/src/app/config/ mtakaki/cachet-url-monitor

and i get this :

Traceback (most recent call last):
File "./cachet_url_monitor/scheduler.py", line 90, in
scheduler = Scheduler(sys.argv[1])
File "./cachet_url_monitor/scheduler.py", line 56, in init
self.configuration = Configuration(config_file)
File "/usr/local/lib/python3.7/site-packages/cachet_url_monitor-0.5-py3.7.egg/cachet_url_monitor/configuration.py", line 84, in init
self.data = load(open(self.config_file, 'r'), Loader=FullLoader)
IsADirectoryError: [Errno 21] Is a directory: 'config/config.yml'

I am a bit confused if i need to clone the repository or i just need to add a yml on my current directory . Also i was wondering if i need to get the repository to the yml file (/usr/src/app/config/) in my current directory.
Thank you in advance for the answers

How to run this in the background?

Hello,

How to run this in the background? I want to update often http websites?

"python cachet_url_monitor/scheduler.py config.yml"

I have server with Debian 9.5 Stretch.

docker-compose file

Hello!

I'm attempting to set up an instance using Docker, and the README suggests that there is a docker-compose file ready for use, however, I can't seem to locate it. Is it meant to be in the repo?

threshold = ?

Is threshold a value in seconds? Or is threshold the number of times before check is marked as a failed?

Example threshold = 5 ...would this prevent changes to cachet until 5 failed checks?

thanks

Running as python daemon

I'm currently utilising screen to keep scheduler.py running in the background, but what would be great is to run as python daemon.

Has anyone managed to do this? There is some information on this here.

Check multiple URLs?

Hi there, I really like this plugin! How could I go and check multiple URLs?
By using multiple config files? How could I load multiple config files?
Thanks
David

Trailing slash in api_url causes 404

Removing the trailing slash from the config file fixes this.

Ubuntu Linux 16
Python: 2.7

<Response [404]>
Traceback (most recent call last):
  File "cachet_url_monitor/scheduler.py", line 77, in <module>
    scheduler = Scheduler(sys.argv[1])
  File "cachet_url_monitor/scheduler.py", line 50, in __init__
    self.configuration = Configuration(config_file)
  File "/home/gardner/cachet-url-monitor/cachet_url_monitor/configuration.py", line 84, in __init__
    self.status = get_current_status(self.api_url, self.component_id, self.headers)
  File "/home/gardner/cachet-url-monitor/cachet_url_monitor/configuration.py", line 56, in get_current_status
    raise ComponentNonexistentError(component_id)
configuration.ComponentNonexistentError: 'Component with id [1] does not exist.'

No module named 'Schedule'

I followed the installation instructions.

Finished processing dependencies for cachet-url-monitor==0.6.7
(cachet-url-monitor) root@S1-Linux-VM:/home/servers/cachet-url-monitor# python3 cachet_url_monitor/scheduler.py config.yml
Traceback (most recent call last):
  File "cachet_url_monitor/scheduler.py", line 8, in <module>
    import schedule
ModuleNotFoundError: No module named 'schedule'

When i trying to install 'Schedule'

(cachet-url-monitor) root@S1-Linux-VM:/home/servers/cachet-url-monitor# pip install schedule
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Requirement already satisfied: schedule in ./lib/python2.7/site-packages (0.6.0)

The URL is unreachable

Doesn't work to me. Got always "The URL is unreachable" no matter what URL I use - even with google.com. Any ideas?

Problem with config.yml

Hi! I have some problem. When me made

[root@bessmertni-poni bin]# docker run -it --rm -v /usr/local/bin/config.yml:/usr/src/app/config/config.yml:ro mtakaki/cachet-url-monitor
Traceback (most recent call last):
  File "cachet_url_monitor/scheduler.py", line 89, in <module>
    scheduler = Scheduler(sys.argv[1])
  File "cachet_url_monitor/scheduler.py", line 55, in __init__
    self.configuration = Configuration(config_file)
  File "/usr/src/app/cachet_url_monitor/configuration.py", line 83, in __init__
    self.data = load(file(self.config_file, 'r'))
  File "/usr/local/lib/python2.7/site-packages/yaml/__init__.py", line 71, in load
    return loader.get_single_data()
  File "/usr/local/lib/python2.7/site-packages/yaml/constructor.py", line 37, in get_single_data
    node = self.get_single_node()
  File "/usr/local/lib/python2.7/site-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()
  File "/usr/local/lib/python2.7/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/usr/local/lib/python2.7/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/usr/local/lib/python2.7/site-packages/yaml/composer.py", line 127, in compose_mapping_node
    while not self.check_event(MappingEndEvent):
  File "/usr/local/lib/python2.7/site-packages/yaml/parser.py", line 98, in check_event
    self.current_event = self.state()
  **File "/usr/local/lib/python2.7/site-packages/yaml/parser.py", line 439, in parse_block_mapping_key
    "expected <block end>, but found %r" % token.id, token.start_mark)**
**yaml.parser.ParserError: while parsing a block mapping
  in "config/config.yml", line 1, column 1
expected <block end>, but found '<block mapping start>'
  in "config/config.yml", line 3, column 3**

it's my config.yml

endpoint:
      url: http://google.com
  method: GET
  timeout: 1 # seconds
  expectation:
    - type: HTTP_STATUS
      status_range: 200-300
    - type: LATENCY
      threshold: 1
    - type: REGEX
      regex: ".*<body>.*"
  allowed_fails: 0
cachet:
  api_url: http://localhost/api/v1
  token: example_my_toker_from_cachet
  component_id: 1
  metric_id: 1
  action:
    - CREATE_INCIDENT
    - UPDATE_STATUS
  public_incidents: true
frequency: 30
latency_unit: ms

What i do wrong?
Thank you!

passing environment variable in the header.

Hi all,

I would like to know the flow for configuration.py with respect to scheduler.py as in how the configuration.py gets loaded. I would also like to know as to where the configuration is stored? How can I make DD-API-KEY' and 'DD-APPLICATION-KEY' as environment variables that can be called into monitor.yaml under header section for URL monitoring? PS : DD-API-KEY' and 'DD-APPLICATION-KEY' are the environment variables I am trying to create and call in the YAML file.

Timeout with valid url

Hi

I am getting "request timed out" message even though the URL works fine when accessed directly. Even if I up the threshold to 15 seconds (much longer than the page response time) it still fails. Also the log (below) says "Failure #1 with threshold set to 0" even with the threshold set to 15 seconds.

Any advice?

     INFO [2018-05-22 13:05:58,896] cachet_url_monitor.configuration.Configuration - Current configuration:
cachet:
  action:
  - CREATE_INCIDENT
  - UPDATE_STATUS
  api_url: https://status.workinconfidence.com/api/v1
  component_id: 1
  metric_id: 1
  public_incidents: true
endpoint:
  allowed_fails: 0
  expectation:
  - status_range: 200-300
    type: HTTP_STATUS
  - threshold: 15
    type: LATENCY
  - regex: .*(<body).*
    type: REGEX
  method: GET
  timeout: 0.01
  url: https://secure.speakinconfidence.com/company/en
frequency: 30
latency_unit: ms

     INFO [2018-05-22 13:05:59,243] cachet_url_monitor.configuration.Configuration - Monitoring URL: GET https://secure.speakinconfidence.com/company/en
     INFO [2018-05-22 13:05:59,244] cachet_url_monitor.configuration.Configuration - Registered expectation: 'HTTP status range: (200, 300)'
     INFO [2018-05-22 13:05:59,244] cachet_url_monitor.configuration.Configuration - Registered expectation: 'Latency threshold: 15.0000 seconds'
     INFO [2018-05-22 13:05:59,244] cachet_url_monitor.configuration.Configuration - Registered expectation: 'Regex: .*(<body).*'
     INFO [2018-05-22 13:05:59,244] cachet_url_monitor.scheduler.Scheduler - Registering action CREATE_INCIDENT
     INFO [2018-05-22 13:05:59,244] cachet_url_monitor.scheduler.Scheduler - Registering action UPDATE_STATUS
     INFO [2018-05-22 13:05:59,244] cachet_url_monitor.scheduler.Scheduler - Starting monitor agent...
  WARNING [2018-05-22 13:06:29,421] cachet_url_monitor.configuration.Configuration - Request timed out
     INFO [2018-05-22 13:06:29,421] cachet_url_monitor.configuration.Configuration - Failure #1 with threshold set to 0
     INFO [2018-05-22 13:06:29,601] cachet_url_monitor.configuration.Configuration - Incident uploaded, API unhealthy: component status [2], message: "Request timed out"

This is the relevant bit from the config file:

endpoint:
  url: https://secure.speakinconfidence.com/company/en
  method: GET
  timeout: 0.01
  expectation:
    - type: HTTP_STATUS
      status_range: 200-300
    - type: LATENCY
      threshold: 15
    - type: REGEX
      regex: '.*(<body).*'
  allowed_fails: 0

latency_unit is read from cachet section

The code behaves differently than documented, the docs says, that latency_unit should be placed in endpoint configuration, but it is read from cachet section:

# The latency_unit configuration is not mandatory and we fallback to seconds, by default.
self.latency_unit = self.data['cachet'].get('latency_unit') or 's'

I can submit a PR once it's clear whether code or docs is the one to follow :-).

Increase code coverage

We don't have a good code coverage and the Scheduler is not well tested. It's essential to have a proper coverage and test all the different edge cases.

'Metric with id [x] does not exist.' but it in Cachet DB

I'm unable to run the script and get the following errors stating that the Metric ID does not exist but for sure it is in the DB.

[email protected]:/var/www/html/cachet-url-monitor# python cachet_url_monitor/scheduler.py config.yml

INFO [2019-05-31 16:06:01,831] cachet_url_monitor.configuration.Configuration - Current configuration:
cachet:
  action: null
  api_url: http://10.0.70.14:80/api/v1
  component_id: 1
  metric_id: 1
  public_incidents: false
endpoint:
  allowed_fails: 1
  expectation:
  - status_range: 200-300
    type: HTTP_STATUS
  - threshold: 1
    type: LATENCY
  - regex: .*<body>.*
    type: REGEX
  method: GET
  timeout: 1
  url: http://www.google.co.uk
frequency: 10
latency_unit: ms

Traceback (most recent call last):
  File "cachet_url_monitor/scheduler.py", line 90, in <module>
    scheduler = Scheduler(sys.argv[1])
  File "cachet_url_monitor/scheduler.py", line 56, in __init__
    self.configuration = Configuration(config_file)
  File "build/bdist.linux-x86_64/egg/cachet_url_monitor/configuration.py", line 108, in __init__
    self.default_metric_value = self.get_default_metric_value(self.metric_id)
  File "build/bdist.linux-x86_64/egg/cachet_url_monitor/configuration.py", line 133, in get_default_metric_value
    raise MetricNonexistentError(metric_id)
cachet_url_monitor.configuration.MetricNonexistentError: 'Metric with id [1] does not exist.'
[email protected]:/var/www/html/cachet-url-monitor#
MariaDB [cachet_data]> select * from metrics;
+----+----------------------+--------+---------------------------------+---------------+-----------+---------------+--------+--------------+-----------+-------+---------------------+---------------------+
| id | name                 | suffix | description                     | default_value | calc_type | display_chart | places | default_view | threshold | order | created_at          | updated_at          |
+----+----------------------+--------+---------------------------------+---------------+-----------+---------------+--------+--------------+-----------+-------+---------------------+---------------------+
|  1 | Website Availability | ms     | Latency for www.google.co.uk |       100.000 |         1 |             0 |      2 |            1 |         5 |     0 | 2019-05-31 14:05:30 | 2019-05-31 14:43:06 |
|  2 | Website Availability | ms     | Latency for www.yahoo.co.uk |       100.000 |         1 |             0 |      2 |            2 |        60 |     0 | 2019-05-31 14:05:30 | 2019-05-31 14:43:10 |
+----+----------------------+--------+---------------------------------+---------------+-----------+---------------+--------+--------------+-----------+-------+---------------------+---------------------+
2 rows in set (0.00 sec)

MariaDB [cachet_data]> 

Monitoring multiple servers

Excuse my ignorance a little, is the idea here to run a virtualenv and a copy of this codebase/config for every server/component, or am i missing something?

is there any way to integrate with AWS Secret server

API keys we provide in config.yaml need to integrate with AWS secret server . for any cloudified environment where the central secret server is the only option to store keys, the current version has the limitation. I appreciate it if anyone takes up this feature to develop.

The URL is unreachable

Why this page is unreachable when it's reachable on browser? I paste log from console. When i add site like google.com it's work.

cachet:
action:

  • CREATE_INCIDENT

  • UPDATE_STATUS
    api_url: ***
    component_id: 1
    public_incidents: true
    endpoint:
    allowed_fails: 0
    expectation:

  • status_range: 200-300
    type: HTTP_STATUS

  • threshold: 10
    type: LATENCY

  • regex: .(<body).
    type: REGEX
    method: GET
    timeout: 10
    url: http://wnuk.it
    frequency: 30
    latency_unit: ms

    INFO [2018-09-23 00:39:18,235] cachet_url_monitor.configuration.Configuration - Monitoring URL: GET http://wnuk.it
    INFO [2018-09-23 00:39:18,236] cachet_url_monitor.configuration.Configuration - Registered expectation: 'HTTP status range: (200, 300)'
    INFO [2018-09-23 00:39:18,237] cachet_url_monitor.configuration.Configuration - Registered expectation: 'Latency threshold: 10.0000 seconds'
    INFO [2018-09-23 00:39:18,237] cachet_url_monitor.configuration.Configuration - Registered expectation: 'Regex: .(<body).'
    INFO [2018-09-23 00:39:18,237] cachet_url_monitor.scheduler.Scheduler - Registering action CREATE_INCIDENT
    INFO [2018-09-23 00:39:18,238] cachet_url_monitor.scheduler.Scheduler - Registering action UPDATE_STATUS
    INFO [2018-09-23 00:39:18,238] cachet_url_monitor.scheduler.Scheduler - Starting monitor agent...
    WARNING [2018-09-23 00:39:51,269] cachet_url_monitor.configuration.Configuration - The URL is unreachable: GET http://wnuk.it
    INFO [2018-09-23 00:39:51,270] cachet_url_monitor.configuration.Configuration - Failure #1 with threshold set to 0
    INFO [2018-09-23 00:39:51,312] cachet_url_monitor.configuration.Configuration - Incident uploaded, API unhealthy: component status [3], message: "The URL is unreachable: GET http://wnuk.it"

Add support to status range

We currently only support a single HTTP status code value, but it would be handy to support a range of values.

Component with id does not exist

Hello,

I'm getting the error 'Component with id does not exist.', are my settings wrong? Can the api read groups using your monitor? Or can't it be in groups?
error

Push latency metrics

We should push the latency metrics, if the metrics id is set, so we can monitor the API responsiveness and lag.

api_url is incorrect when CachetHQ send a email in button "manage subscriptions"

with the following docker-compose (I'm behind a reverse proxy: traefik)

version: "3"

services:
  postgres:
    image: postgres:10-alpine
    volumes:
      - ./db_data:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=postgress
      - POSTGRES_PASSWORD=postgress
      - POSTGRES_DB=postgress
    networks:
      - cachethq_internal
    restart: always

  cachet:
    image: cachethq/docker:2.3-latest
    networks:
      - ak_cachethq_outside
      - ak_cachethq_internal
#    environment:
#...
    depends_on:
      - postgres
    restart: always
  cachet_url_monitor:
    image: mtakaki/cachet-url-monitor
    networks:
      - ak_cachethq_internal
    depends_on:
      - cachet
    volumes:
      - ${PWD}/.config.yml:/usr/src/app/config/config.yml:ro
    restart: always

networks:
  cachethq_outside:
    external:
      name: traefik_proxy
  cachethq_internal:
    driver: bridge

And the following configuration:

endpoint:
  url: https://myworpresspage.com
  method: GET
  timeout: 1 # seconds
  expectation:
    - type: HTTP_STATUS
      status_range: 200-300
    - type: LATENCY
      threshold: 1
    - type: REGEX
      regex: ".*WORDPRESS FOOTER HOOK.*"
  allowed_fails: 0
cachet:
  api_url: http://cachet:8000/api/v1
  token: xxxxxxxxxxxxxxxxxxx
  component_id: 1
  metric_id: 1
  action:
    - CREATE_INCIDENT
    - UPDATE_STATUS
  public_incidents: true
frequency: 30
latency_unit: ms

It works perfectly, but when cachetHQ sends an email, in the URL inside the email, redirects me to http://cachet:8000/subscribe/manage/xxxxxxx instead of https://status.myworpresspage.com/subscribe/manage/xxxxxxx in button "manage subscriptions"

I do not understand the API very well, but you could place an API URL and a LINK (A hyperlink to the component)???

InsecurePlatformWarning

InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings

Running this from a shared hosting site, what is the minimum version requirement for this script? We are on python 2.6 atm.

Receiving "Unexpected HTTP status (200)" when status_range: 200

Except from config.yml

    expectation:
      - type: HTTP_STATUS
        status_range: 200
        incident: MAJOR

Except from logs:

cachet-url-monitor    |      INFO [2020-02-05 22:38:41,228] cachet_url_monitor.configuration.Configuration.example backend - Component current status: ComponentStatus.MAJOR_OUTAGE
cachet-url-monitor    |      INFO [2020-02-05 22:38:41,228] cachet_url_monitor.configuration.Configuration.example backend - Monitoring URL: GET https://example.com
cachet-url-monitor    |      INFO [2020-02-05 22:38:41,228] cachet_url_monitor.configuration.Configuration.example backend - Registered expectation: 'HTTP status range: [200, 201['
cachet-url-monitor    |      INFO [2020-02-05 22:38:41,228] cachet_url_monitor.scheduler - Registering action CREATE_INCIDENT
cachet-url-monitor    |      INFO [2020-02-05 22:38:41,228] cachet_url_monitor.scheduler - Registering action UPDATE_STATUS
cachet-url-monitor    |      INFO [2020-02-05 22:38:41,228] cachet_url_monitor.scheduler.Scheduler - Starting monitor agent...
...
cachet-url-monitor    |      INFO [2020-02-05 22:39:11,396] cachet_url_monitor.configuration.Configuration.example backend - Unexpected HTTP status (200)
cachet-url-monitor    |      INFO [2020-02-05 22:39:11,537] cachet_url_monitor.configuration.Configuration.example backend - Component update: status [ComponentStatus.MAJOR_OUTAGE]
cachet-url-monitor    |      INFO [2020-02-05 22:39:41,708] cachet_url_monitor.configuration.Configuration.example backend - Unexpected HTTP status (200)
cachet-url-monitor    |      INFO [2020-02-05 22:39:41,708] cachet_url_monitor.configuration.Configuration.example backend - No changes to component status.

At first I thought it may be a parsing issue, looking at this line of the log
cachet_url_monitor.configuration.Configuration.example backend - Registered expectation: 'HTTP status range: [200, 201['
But from the code that seems to be expected.

Monitor Multple URLs

Is it currently possible to monitor multiple URL's? I've tried entering multiple URL's into the config.yml file using the same format as the single URL example, making sure that each has the correct component ID, but only 1 seems to be checked and updated.

Expectation validation is not working properly

When creating a config, if the expectation is not a valid option is just fail with a non-descriptive exception:

Traceback (most recent call last):
  File "cachet_url_monitor/scheduler.py", line 54, in <module>
    scheduler = Scheduler(sys.argv[1])
  File "cachet_url_monitor/scheduler.py", line 32, in __init__
    self.configuration = Configuration(config_file)
  File "/usr/src/app/cachet_url_monitor/configuration.py", line 43, in __init__
    in self.data['endpoint']['expectation']]
  File "/usr/src/app/cachet_url_monitor/configuration.py", line 152, in create
    return expectations.get(configuration['type'])(configuration)
TypeError: 'NoneType' object is not callable

It should also list the available options.

SSL Failed Certificate Verification Error

Trying to set up the url monitor with my status page and I'm getting this error:

(cachet_url_monitor) $ python cachet_url_monitor/scheduler.py config.yml

Traceback (most recent call last):
  File "cachet_url_monitor/scheduler.py", line 89, in 
    scheduler = Scheduler(sys.argv[1])
  File "cachet_url_monitor/scheduler.py", line 55, in __init__
    self.configuration = Configuration(config_file)
  File "/Users/username/Development/Web/Cachet/cachet-url-monitor/cachet_url_monitor/configuration.py", line 91, in __init__
    self.default_metric_value = self.get_default_metric_value()
  File "/Users/username/Development/Web/Cachet/cachet-url-monitor/cachet_url_monitor/configuration.py", line 106, in get_default_metric_value
    get_metric_request = requests.get('%s/metrics/%s' % (self.api_url, self.metric_id), headers=self.headers)
  File "/Users/username/Development/Web/Cachet/cachet-url-monitor/cachet_url_monitor/lib/python2.7/site-packages/requests/api.py", line 67, in get
    return request('get', url, params=params, **kwargs)
  File "/Users/username/Development/Web/Cachet/cachet-url-monitor/cachet_url_monitor/lib/python2.7/site-packages/requests/api.py", line 53, in request
    return session.request(method=method, url=url, **kwargs)


  File "/Users/username/Development/Web/Cachet/cachet-url-monitor/cachet_url_monitor/lib/python2.7/site-packages/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/username/Development/Web/Cachet/cachet-url-monitor/cachet_url_monitor/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
File "/Users/username/Development/Web/Cachet/cachet-url-monitor/cachet_url_monitor/lib/python2.7/site-packages/requests/adapters.py", line 447, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)

NameError: name 'file' is not defined

Hi,

I've installed the package via pip, when adding the config.yml file and starting it via : python3 scheduler.py config.yml I get the following error message :

Traceback (most recent call last):
File "scheduler.py", line 89, in
scheduler = Scheduler(sys.argv[1])
File "scheduler.py", line 55, in init
self.configuration = Configuration(config_file)
File "/usr/local/lib/python3.7/site-packages/cachet_url_monitor/configuration.py", line 83, in init
self.data = load(file(self.config_file, 'r'))
NameError: name 'file' is not defined

any idea how to solve this?

Jay

Create incidents whenever the checks fail

We should be creating incidents whenever a check fails. At the moment we're only updating the component status and we're not creating incidents, which are more descriptive of what happens and adds a timeline to it.

config.yml file seg fault when passing value rapped in " "

I am using your contianer image in a Kubernetes / OpenShift 3.3 deployment. I gotten to work really well and wanted to rap it up as a PaaS offering. One item that is odd about k8s is that you can not just mount a config file but use configmap. This worked great and was able to get your container to work.

I then figured i make this in to a template. I setup the template but in the parameter section boolean and numbers base values have to ramped in " " or it fails validation. Well when these params are passed to the container as a configmap all the values are still ramped in " " and your app seg faults. Was not sure if there was a way to say " " rapped value is still valid.

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.