Skip navigation
4214 Views 6 Replies Latest reply: Jul 10, 2012 5:49 PM by jcurry RSS
joanypony Rank: Green Belt 114 posts since
Mar 7, 2012
Currently Being Moderated

Jul 4, 2012 6:44 AM

Zenoss and DNS/IP refresh

Hi All,

We've had Zenoss in production for approximately 3 months and I've just discovered a "feature" that seems to be well known. If I add a device by its hostname, it's stored by its IP. Zenoss doesn't do a DNS lookup on the hostname after this and just saves the IP forever and ever. 

 

If for example, you are monitoring external feeds that occasionally change their backend datacenters, Zenoss doesn't notice this, but continues to monitor the original IP. This means that this monitor is giving us incorrect/invalid data.

 

I want Zenoss to automatically do a DNS lookup against each device and to reset the IP if necessary.

I cannot do this as an event transform, as the majority of the time, no event is generated, the data source has just changed and while the latency is affected, it doesn't cause errors.

 

I know that within ZenDMD I can use

 

for dev in dmd.Devices.getSubDevices_recursive():

...      dev.setManageIp()                          

...      commit()

 

 

But how can I get Zenoss to do this as part of regular monitoring and checks?

 

Is my only option to write a script and call this as a command within a monitoring template?

 

Regards,

Joan

  • jmp242 ZenossMaster 4,060 posts since
    Mar 7, 2007
    Currently Being Moderated
    1. Jul 5, 2012 8:47 AM (in response to joanypony)
    Re: Zenoss and DNS/IP refresh

    Pretty much. Zenoss uses IP addresses as the key and unique ID of devices in Zenoss Core. The problem with always doing a DNS lookup is you're dependant on DNS working to determine if anything else is. The targetted market (I believe) was internal monitoring, so most server networks use static IP addresses.

     

    That said, it is a long standing feature request to enable (selectively I think) DNS queries for devices... I might suggest doing it as part of modelling, but then that only helps every 12 hours, so if the IPs are changing more frequently than that... yea, I guess as part of a command datasource or just straight crontask?

     

    --

    James Pulver

    ZCA Member

    LEPP Computer Group

    Cornell University

  • jcurry ZenossMaster 1,021 posts since
    Apr 15, 2008
    Currently Being Moderated
    2. Jul 7, 2012 7:39 AM (in response to joanypony)
    Re: Zenoss and DNS/IP refresh

    Hi Joan,

    This isn't the way it works for me!

     

    I always discover by fully-qualified domain name and that is used as the id field of the device.  The id is also propagated automatically to the title field.  Separately you have the manageIp field with the address.

     

    If I discover a device by IP address that is resolvable, then the id field is the IP address, the title field has automatically done a DNS lookup and has the dns name and manageIp is the IP address.

     

    I use zendmd to check this eg.

    zendmd

    dev=find('hp7410.skills-1st.co.uk')

    print dev.id

    print dev.title

    print dev.manageIp

     

    Cheers,

    Jane

  • alex0cy Rank: White Belt 58 posts since
    May 13, 2008
    Currently Being Moderated
    4. Jul 9, 2012 10:21 AM (in response to joanypony)
    Re: Zenoss and DNS/IP refresh

    The solution is relatively simple in case you can use custom monitoring scripts. You shall create command template and call script in the way like 'my_monitoring_script ${dev/id}'. In this case your device id in zenoss, which is usually a hostname will be passed to your script instead of ip address.

  • themactech Rank: Brown Belt 537 posts since
    Apr 13, 2009
    Currently Being Moderated
    5. Jul 9, 2012 10:30 AM (in response to alex0cy)
    Re: Zenoss and DNS/IP refresh

    How about a custom monitoring script that would pass the ManageIP and the DeviceName as variables, then do a DNS lookup and compare the result.  If the DNS lookup returns a new IP address for the device, then it changes the device's ManageIP via ZenDMD.

     

    Being a command script it would run every polling session.

     

    Manuel

  • jcurry ZenossMaster 1,021 posts since
    Apr 15, 2008
    Currently Being Moderated
    6. Jul 10, 2012 5:49 PM (in response to themactech)
    Re: Zenoss and DNS/IP refresh

    Here is a quick Python script that checks dns lookups against the id of a device and it's manageIp field.  It isn't pretty but it does seem to work.  It assumes that you have a fully-qualified DNS name as the id field for the device and it assumes that DNS will always give you the correct address for that name.

     

    #!/usr/bin/env python

    # Author:               Jane Curry

    # Date:                 10th July 2012

    # Copyright:            Skills 1st Ltd

    # Description:          Check dns resolution has not changed

    #                       expects dev/id and dev/manageIp as input parameters

    #

    # Updates:

    #

     

    # Perform initial imports.

    import os, sys, getopt

    import logging

     

    # Perform Zenoss specific imports.

    import Globals

    from Products.ZenUtils.ZenScriptBase import ZenScriptBase

    from transaction import commit

     

    if len(sys.argv) < 3:

      sys.exit('Usage: %s  dev/id dev/manageIp ' % sys.argv[0])

     

    name=sys.argv[1]

    #print 'name is' + name

    ip=sys.argv[2].strip()

     

    # dig +short simply returns one or more IP addresses that DNS resolves for the supplied name

    nameres = os.popen('dig +short %s' % (name) )

    if ip in (i.strip() for i in nameres.readlines() ):

      print 'No DNS change - OK | statusvar=0'

      sys.exit(0)

    else:

      print 'Change in DNS - WARNING | statusvar=1'

    # Get first response again from dig

      nameres = os.popen('dig +short %s' % (name) )

      dnsip = nameres.readline().strip()

      dmd = ZenScriptBase(connect=True).dmd

      dev=dmd.Devices.findDevice(name)

      dev.setManageIp(dnsip)

      commit()

      sys.exit(1)

     

    I have attached this to a Command template that runs the script.  The data source has a datapoint variable called statusvar (that has to match the variable name in the print output from the script).  Basically statusvar is 0 for no change and 1 if there has been a change.

    Make sure that your command data source is passed ${dev/id} and ${dev/manageIp}. 

     

    I have set a cycle time of 60 for testing but probably something more like every hour or even every day is more realistic.  Be aware that if you change the cycle time, you will wreck any existing data in the datafile for the statusvar variable - you should find this datafile rrd under $ZENHOME/perf/Devices/<your device name> and delete the old datafile once you have changed the cycle time.

     

    dns_check_change.jpg

    I'm sure someone can refine this.

    I'm even more sure someone will tell me if it doesn't work for them

     

    Cheers,

    Jane

More Like This

  • Retrieving data ...

Legend

  • Correct Answers - 4 points
  • Helpful Answers - 2 points