Using NodePing with Ansible

Ansible is a configuration management and application deployment tool that is designed to help automate IT. NodePing offers a module that allows our customers who use Ansible in their infrastructure to automate tasks such as managing checks and creating ad-hoc and scheduled maintenance with our maintenance feature. For example, you can include setting up monitoring in your Ansible playbook, so new servers or virtual machines are automatically added to your monitoring.  Or, if you have a playbook that automates maintenance, you can have Ansible set ad-hoc maintenance on your monitoring for the affected host before it runs the rest of the playbook.

 

Getting Started

To get started with the NodePing Ansible modules, you will have to download the modules and copy them to your Ansible modules directory. You may have to edit your ansible.cfg. The path is configured via the library variable and by default is /usr/share/my_modules/. You can download the zip file here with the Ansible modules and extract them to your computer. In the unzipped folder you should find two Python files: nodeping.py and nodeping_maintenance.py. These two files should be copied into your Ansible library (modules) folder. There are also a couple example playbooks that show you a snippet of using the nodeping and nodeping_maintenance modules.

The NodePing Ansible module depends on the nodeping-api library for Python. This can be installed using the pip package manager, like so:

# python2

pip install nodeping-api

# python3
pip3 install nodeping-api

# Alternate python3
python3 -m pip install nodeping-api

# If installed for the user
python3 -m pip install --user nodeping-api

Creating Checks

You can create checks with the NodePing module, and if you need to access any of the values from the result after creation, you can register the result and access it elsewhere in your playbook. Here is an example:


---
- hosts: test
  
  vars:
    nodeping_api_token: secret-token-here
    
  tasks:
    - name: Create a NodePing check for target host
      delegate_to: localhost
      nodeping:
        action: create
        checktype: PING
        target: "{{ ansible_default_ipv4.address }}"
        label: mytest ping
        enabled: False
        interval: 1
        token: "{{ nodeping_api_token }}"
        notifications:
        - group: My Contact Group
          notifydelay: 2
          notifyschedule: All the time
        - contact: 4QT82
          notifydelay: 0
          notifyschedule: All the time
      register: result

Note that the checktype is in all caps. This will be necessary when creating a check. Our API documentation provides a list of check types as well as parameters for creating the check. It is recommended that you delegate the task to localhost if you can. That way your deployment server is the only server that needs the Python library installed. If you wish to create your checks on the target server, be sure to install the nodeping-api package via the pip module. The returned value is registered to the variable result and stored as a dictionary, so you can access the values easily. In this next example, the check id is used to get the check contents from NodePing:


- name: Get a check, run from localhost
  delegate_to: localhost
  nodeping:
    action: get
    checkid: "{{ result.message._id }}"
    token: "{{ nodeping_api_token }}"

Here you can see we queried result.message._id of the result we registered earlier. This is an example of how you can use data returned from NodePing through the rest of your playbook for whatever your needs may be. You can also get check info by providing a label, but note that if you have many checks with the same label, it will grab only the first one.

 

Maintenance

The Maintenance functionality will let you disable a list of checks while you do work on your server. That way, you can do your maintenance work on your server without it affecting your uptime during planned operations. An example of using this could be running the nodeping_maintenance module to disable your checks. It will take about 30 seconds for the maintenance schedule to start once created. You will want to ensure services aren’t being stopped or servers rebooted while the changes propogate across our distributed service and make sure all of your checks are disabled. At that point you can take your services offline without affecting your uptime metrics. Once the set duration is complete, NodePing will automatically enable those checks again. Here you can see an example of creating an ad-hoc maintenance that lasts for 30 minutes.

tasks:
  - name: Create ad-hoc maintenance
    delegate_to: localhost
    nodeping_maintenance:
      token: "{{ nodeping_api_token }}"
      name: ad-hoc maintenance
      duration: 30
      scheduled: False
      checklist:
        - 201911191441YC6SJ-4S9OJ78G
        - 201911191441YC6SJ-XB5HUTG6

  - name: Pause a minute to ensure checks are disabled
    pause:
      seconds: 30

# ...do stuff

You can also set scheduled to True, and provide a cron-syntax schedule to create a recurring maintenance.

Life is Easier with Automation

Pairing your Ansible automation with NodePing monitoring is a great way to automate processes, making them both easier and increasing reliability and trust in your systems.  We hope this module and other tools for integrating NodePing into your infrastructure management will make life easier and help you get the job done. If you aren’t using NodePing yet, you can sign up for a free, 15-day trial and test out monitoring your services today and take advantage of integrating NodePing monitoring and maintenance in your Ansible playbooks.

Probe Server Change [AR]

The following probe server will be changing IP addresses on 2020-06-04:

Federal, Argentina (AR)

(190.210.176.48)
to
(190.104.217.135)

Please adjust your firewalls appropriately if you whitelist so your checks do not fail because of the probe IP address changes.

An always current and updated list of all the IP addresses for our probe servers can be found in the FAQ, a text file, and via DNS query, probes.nodeping.com.

[UPDATE – 2020-06-04 11:28GMT-7] – IP change complete.

On-demand Diagnostics API and from AGENT Checks

It isn’t always obvious what’s going on when a check fails and additional information about what our probes are seeing can be helpful for troubleshooting. The NodePing diagnostic tools allow you to run several utilities to get information about what our probes are seeing. Now we’ve brought that functionality to our AGENT checks as well as a new API endpoint.

Diagnostics from AGENTs

You can now connect your AGENT checks to our diagnostics servers to run our most useful tools: mtr, ping, traceroute, and dig. Use the instructions in the AGENT software to run the diagnostic client on your AGENT. Your AGENTs will appear in the ‘location’ dropdown of the Diagnostic Tools in NodePing.

Diagnostics API

On-demand diagnostics can now be requested via our REST API. Your integrations can request NodePing diagnostics from any of our probes as well as from your AGENTs with a simple HTTP request. Please see the diagnostics API documentation for details.

If you don’t have a NodePing account, you can sign up for a free, 15-day trial and experience the fast and accurate service NodePing provides.

Probe Server Changes [UK,RO]

The following probe server will be changing IP addresses on 2020-04-15:

Bucharest, Romania (RO)

(89.45.10.135 / 2a04:9dc0:1::79a4:725e)
to
(185.158.248.112 / 2a04:9dc0:0:4:185:158:248:112)

 

In addition, the following probe server will be changing IP addresses and location on 2020-04-15:

Rugby, England (UK)

(78.157.200.148 / 2a01:a500:375:1::25:4617)
to
Thames Valley, England (UK)

(109.169.10.173 / 2001:1b40:5000:2a:216:3eff:fed9:fd3c)

 

Please adjust your firewalls appropriately if you whitelist so your checks do not fail because of the probe IP address changes.

An always current and updated list of all the IP addresses for our probe servers can be found in the FAQ, a text file, and via DNS query, probes.nodeping.com.

[UPDATE – 2020-04-15 11:23GMT-7] – IP changes complete.

Monitoring Private Networks with NodePing

NodePing has been providing distributed Internet availability monitoring since 2011.  During that time we’ve made billions of HTTP requests, connected to a huge number of SSH servers, and sent boat loads of PINGs.  Our systems have been listening for dropped volume levels on audio feeds, verifying SSL certificates, testing the response from email servers, checking DNS servers, and monitoring a whole slew of Internet services on every continent (except for Antarctica, yet).

undefinedThe missing component, until recently, was monitoring for private networks.  All of the monitoring mentioned above was availability monitoring from the Internet and required access through periphery firewalls to services.  That works well for public facing services, but it leaves out a lot of services and systems that are not (and should not be) publicly accessible. We’ve been working for a few years to find just the right approach to safely and reliably provide private network monitoring, and we think we’ve found it in our new AGENT check type.

Our AGENT check allows you to install a small agent on a machine in your local network and run most of our standard check types just about anywhere you have a Linux box available.  The software is small and very efficient, and is a really easy install. Once it is running, you can assign checks to your private location using our normal UI, or through our API.

The agent runs on node.js, and the code is available on github for you to review and audit.  The software can run under a regular user, and does not need any elevated privileges. Only your account has access to run checks on your agent instances.

So now you can easily assign PING, HTTP, SSH, DNS, PORT, and most of our other check types to a machine on your private network, to monitor services that should not be accessible from the Internet.  Monitor your private Intranet, make sure your private database servers are accepting connections on your network, and verify internal DNS responses. This solution scales well, is easy to start, simple to maintain, and like the rest of NodePing’s monitoring services, it just works.

Since our AGENT check runs our standard check types, it is a great compliment to our PUSH check type, which remains available and actively supported as well.  The PUSH check type is designed for you to customize and monitor basically anything on your local machine that is quantifiable by a local script. Together, these check types allow you to fully monitor your private networks and resources, safely and reliably.

The AGENT check is available now on all Provider accounts. If you don’t have a NodePing account yet, we offer a 15 day free trial.  Give it a try!

Maintenance

Exclude planned downtime from your check uptime statistics using our newly released maintenance features.

All services need maintenance now and again. Required restarts and reboots usually mean services will be offline while security patches and updates are applied. Many SLA’s and Terms of Service exclude these kinds of activities from your uptime commitments, so disabling your checks during those down times is appropriate.  You also often don’t need notifications for planned events.

NodePing’s maintenance features make it simple to manage your monitoring for planned maintenance. You can create recurring and ad-hoc maintenance that will disable your selected checks for a user-specified duration in minutes.  It will then re-enable the checks after the time you specify, and if any of the checks are still failing at that point–maybe a service failed to restart–you’ll receive the regular ‘down’ notifications.

Some examples where maintenance comes in handy:

  • If your nightly database backup causes your HTTP checks to time out, create a recurring maintenance to disable those HTTP checks for the 3 minutes it takes to do the backup.
  • If your VPS provider sends an emergency maintenance email saying they’re replacing the router and to expect some network interruptions for the next hour, you can set the affected checks in an ad-hoc maintenance that will re-enable them after an hour.

Our new maintenance features will help you maintain your SLAs and alert you right away if your checks fail after maintenance is complete.

Recurring maintenance can be set using a familiar cron expression.

You can find information in our documentation about our maintenance features and the new maintenance API endpoint.

If you don’t yet have a NodePing account, please sign up for a free, 15-day trial and see if our reliable uptime monitoring is a good fit for you.

Probe Server Change [OR] and Addition [OT]

The following probe server will be changing IP addresses and location on 2020/01/22:

Portland, Oregon (OR) – USA is changing from
(162.210.173.188 / 2604:b480:ffff:ffff:fa06::10)
to
Hillsboro, Oregon (OR) – USA
(147.135.38.178 / 2604:2dc0:200:b2::10)

We’re also adding a new probe to the North America region on 2020/01/22:
Toronto, Ontario (OT) – CA
(172.105.6.187 / 2600:3c04::f03c:92ff:fe9b:dd03)

Please adjust your firewalls appropriately if you whitelist so your checks do not fail because of the probe IP address changes.

An always current and updated list of all the IP addresses for our probe servers can be found in the FAQ, a text file, and via DNS query, probes.nodeping.com.

[UPDATE – 2020-01-22 13:03GMT-7] – IP change and probe addition complete.

Probe Server Change [IL]

The following probe server will be changing IP addresses on 2019-12-12:

Chicago, Illinois (IL) – USA

(96.9.222.119 / 2602:ffc8:3d02::190:4ae6)
to
(172.93.197.58 / 2602:ffc8:1:14:225:90ff:fee6:8f90)

 

Please adjust your firewalls appropriately if you whitelist so your checks do not fail because of the probe IP address changes.

An always current and updated list of all the IP addresses for our probe servers can be found in the FAQ, a text file, and via DNS query, probes.nodeping.com.

[UPDATE – 2019-12-12 12:53 GMT-6] – IP change complete.

DNSSEC Monitoring

Your DNSSEC implementation is an important part of increasing authentication for your DNS data. NodePing’s DNS check can now verify DNSSEC authenticated data.

To monitor DNSSEC, NodePing uses public key cryptography to verify the digital signature in the data all the way back to the root servers. If there’s an issue anywhere in the chain, you’ll be the first to know with NodePing’s fast and accurate notifications.

Designed to protect DNS clients from using forged or modified DNS data, DNSSEC ensures the information in the DNS reply is identical to what the owner of the DNS zone has digitally signed and published on their authoritative nameservers.

Only enable DNSSEC verification in your NodePing checks if your nameservers have that functionality.

If you do not yet have a NodePing account, please sign up for our free, 15-day trial. We’re confident you’ll find our uptime monitoring to not only be the fastest and most accurate, but also a great value.

Using NodePing’s API with Python

Over the years, NodePing has offered an API to manage most aspects of your monitoring. Today, we are introducing our new Python 2/3 library to interface with this API. Instead of reinventing the wheel in your code to interact with our API, drop this library into your project and with a few lines you can easily manage your checks and various other aspects of your account. With the Python library at your disposal, you can:

  • List, create, update, and delete checks
  • Manage contacts
  • Manage contact groups
  • Manage schedules
  • Get check results and uptime
  • Get notification information
  • Get probe information

This means that the Python library has feature parity with our API. You can get the code from our GitHub repository or install it from Pypi via pip. There is also some documentation written to help you by providing snippets of what your code might look like when querying the API with Python.

In this post, we will share a brief introduction to getting started with using the Python library and how it can be used to manage your account. You can use your installer of choice, but in this introduction I will use pip to install the library:


pip install nodeping-api

 

You may have to specify Python2 or 3 for your pip version, depending on your system. To start using the library, you will need to provide your API token as a variable, and an optional subaccount ID to start managing your checks.

 

From here, you can do things such as list failing checks:


#!/usr/bin/env python
# -*- coding: utf-8 -*-

""" Demo for Python library
"""

from pprint import pprint
from nodeping_api import get_checks

def main():
    """ Main function
    """

    token = 'my-secret-token'

    query = get_checks.GetChecks(token)
    checks = query.failing_checks()

    pprint(checks)

if __name__ == '__main__':
    main()

 

This example will collect all your failing checks and return them to be used in a dictionary format. The output might look something like this:

{'2019052211307H0IX-KCGJCX1X': {'_id': '2019052211307H0IX-KCGJCX1X',
    'created': 1563471438952,
    'customer_id': '2019052211307H0IX',
    'dep': False,
    'enable': 'active',
    'firstdown': 1563471472497,
    'homeloc': False,
    'interval': 3,
    'label': 'Test Check',
    'modified': 1563471438952,
    'notifications': [],
    'parameters': {'follow': False,
        'ipv6': False,
        'sens': 2,
        'target': 'https://notreal.nodeping.com/',
        'threshold': 5},
    'public': False,
    'queue': 'utcoCpoUJx',
    'runlocations': False,
    'state': 0,
    'status': 'assigned',
    'type': 'HTTP',
    'uuid': 've8s9sgj-j588-4li3-9ytp-1kho9wtutriy'}}

 

You can also create checks. For example, here is a basic idea of creating an HTTP check:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

""" Demo for Python library
"""

from pprint import pprint
from nodeping_api import create_check

def main():
    """ Main function
    """

    token = 'my-secret-token'

    target = 'https://nodeping.com'
    enabled = True
    public = False
    interval = 1
    runlocations = 'nam'

    created = create_check.http_check(
        token,
        target,
        label="Check NodePing",
        enabled=enabled,
        public=public,
        interval=interval,
        runlocations=runlocations
    )

    pprint(created)

if __name__ == '__main__':
    main()

 

Along with the output when the check is created. Note that it is in a dictionary format, but pretty printed so it’s easier to read here:

{'_id': '2019052211307H0IX-WEOR7GAH',
 'change': 1563474539024,
 'created': 1563474539024,
 'customer_id': '2019052211307H0IX',
 'dep': False,
 'enable': 'active',
 'homeloc': False,
 'interval': 1,
 'label': 'Check NodePing',
 'modified': 1563474539024,
 'parameters': {'follow': False,
                'ipv6': False,
                'sens': 2,
                'target': 'https://nodeping.com/',
                'threshold': 5},
 'runlocations': ['nam'],
 'public': False,
 'status': 'modified',
 'type': 'HTTP',
 'uuid': '1fog8q51-zdhv-4vmb-832r-tsun0o9unt3f'}

 

You can also get your uptime from a certain time interval. In this example, you can find what your uptime is since July, 2019

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from nodeping_api import results
from pprint import pprint


def main():
    """
    """

    token = 'my-secret-token'
    check_id = 'my-check-id'

    # Get uptime since July, 2019
    uptime_results = results.get_uptime(token, check_id, start="2019-07")

    pprint(uptime_results)


if __name__ == '__main__':
    main()

 

This will give you an output that looks something like this:
{'2019-07': {'down': 2154131, 'enabled': 2678400000, 'uptime': 99.92},
'2019-08': {'down': 88733, 'enabled': 753256766, 'uptime': 99.988},
'total': {'down': 2242864, 'enabled': 3431656766, 'uptime': 99.935}}

This is only a snippet of what the library can do, and the documentation is detailed to get you started on your journey. Give it a try and see how you can improve your uptime monitoring in your Python projects. This code is free and available to download. We encourage pull requests for new features so if you make changes or have requests, feel free to share.

If you aren’t using NodePing yet, you can sign up for a free, 15-day trial and test out monitoring your services today and take advantage of our API in your own Python projects.