Forum Discussion

Kirby_Timm's avatar
3 months ago
Solved

Programmatic Ping Alert

We currently lack the ability to white list domain names on our firewall, so I have to do everything via IP.  Recently I’ve come across an issue where a company won’t give me their external IP’s because they can change, or so they say.  For several weeks I’ve pinged the IP’s and it has always been 1 of 4 IPs.  Has anyone created some kind of ping alert that does something like “ping easypost.com and api.easypost.com if the IP’s returned are not in 169.62.110.130-169.62.110.133, alert me”  I’m not much of a programmer myself so I’d need something pretty “plug and play”.

TIA!

  • plug-n-play, not likely for this use case. 

    It seems like you need to monitor the DNS resolution and update your synthetic check based on the IP that the DNS resolves to. Does that about sum it up?

    If so, this is definitely not going to be something that’s just plug-n-play. You’ll need to write a microservice to monitor the DNS and whenever the resolved IP address changes, hit the LM API to patch the synthetic check to update the IP address. All of this is doable, but depending on your level of comfort, you may want to pursue other avenues (start preaching the we-need-to-be-able-to-whitelist-domains argument).

3 Replies

  • plug-n-play, not likely for this use case. 

    It seems like you need to monitor the DNS resolution and update your synthetic check based on the IP that the DNS resolves to. Does that about sum it up?

    If so, this is definitely not going to be something that’s just plug-n-play. You’ll need to write a microservice to monitor the DNS and whenever the resolved IP address changes, hit the LM API to patch the synthetic check to update the IP address. All of this is doable, but depending on your level of comfort, you may want to pursue other avenues (start preaching the we-need-to-be-able-to-whitelist-domains argument).

  • Yeah, already preaching the “we need a new firewall” and it should be happening this year.  I was just hoping for something I might be able to do in the meantime.  My programming skills consist of 
    10 print “hello”
    20 goto 10
    So not likely to be something I’ll be programming anytime soon.  Oh well.  Thanks for the reply!

  • ChatGPT is your friend.

    Taking this a step further, you could expand this to run every N seconds and update LM when there’s a change. This makes use of my lmwrapper and the SDK to make the code simple. You could run this on one of your collectors assuming python is installed. You’ll need to get the website_id of the website that needs to be updated. This can be found by going to the website in UIv4 (shock!) and getting the URL when the desired website is selected. My URL looks like this:

    /santaba/uiv4/websites/treeNodes#websiteGroups-1*,websiteGroups-60,websiteGroups-174,websites-113

    Where 113 is the ID of the website I am looking at in the UI.

    import socket
    from time import sleep
    from lm import lm

    # this is the number of seconds between checks of the DNS record
    n = 30

    # this is the ID of the website in LM to update
    website_id = 123456789

    # this is the FQDN of the target
    fqdn = "easypost.com"

    existing_ip = ""
    # start an infinite loop (Ctrl+C to exit)
    while True:

    # resolve the DNS name to IP
    try: current_ip = socket.gethostbyname(fqdn)
    # do this if there's an issue resolving the DNS
    except socket.gaierror as e: print(f"Error resolving the DNS for {fqdn}: {e}")

    # if the IP we got during the last cycle is different from the IP we got on the previous line, we need to update LM
    if existing_ip != current_ip:

    # update LM
    response = lm.patch_website_by_id(website_id, {"host": current_ip})

    # as long as the update was successful, remember the new IP as the current IP
    if response: existing_ip = current_ip
    # what to do if there's an error updating LM
    else: print("There was an error updating the website.")

    # wait N seconds before doing it all again
    sleep(n)

    That’s about as plug and play as you’re going to get.