Ubuntu – Can nagios3 automatically generate a network map

10.04nagios3networkingserver

Have just installed nagios3 onto Ubuntu Server 10.04. A clean install. All plugins installed.

The nagios status map only has localhost and gateway discovered. Is there a way for it to scan our network, along with all Windows servers, routers, etc?

I can't find any automated way to do this.

Our network is a large school network so manual configuration is difficult.

Best Answer

Have you tried check_find_new_hosts plugin ? You can find how it works in the attached readme here.

usage:
check_find_new_hosts [-v+] [-x] [-s] /dir ip netmask contact

where:
dir is the directory containing the .cfg files (and .skip files if you want to skip certain hosts)
ip is an ip in the range you want to scan
netmask is an integer standing for the netmask eg:24 = 255.255.255.0
contact is the contact group you want new hosts found to answer to.

example:
./check_find_new_hosts -v /etc/nagios/network 192.168.10.129 25 domain-admins


when troubleshooting how this is working use -vv or -vvv from a command line
for more information consult the very very verbose help (may want to | less on a small screen):
./check_find_new_hosts -vvvh

----------------------------------------------------------------------------------------------------------------------------------------
check_find_new_hosts requires the following (that I know of):

1)  fping is installed at /usr/sbin/fping
2)  traceroute is installed at /usr/sbin/traceroute
3)  Nagios must parse a directory of cfg files, rather than implicitly listing the files eg:

    cfg_dir=/etc/nagios/hosts_hostgroups_and_services
    rather than:
    #cfg_file=/etc/nagios/contactgroups.cfg
    #cfg_file=/etc/nagios/contacts.cfg
    #cfg_file=/etc/nagios/dependencies.cfg
    #cfg_file=/etc/nagios/escalations.cfg
    #cfg_file=/etc/nagios/hostgroups.cfg
    ...
4)  the service generic_service must be defined (the following is what I use):

define service{
    name                generic-service ; The 'name' of this service template, referenced in other service definitions
    active_checks_enabled       1   ; Active service checks are enabled
    passive_checks_enabled      1   ; Passive service checks are enabled/accepted
    parallelize_check       1   ; Active service checks should be parallelized (disabling this can lead to major performance problems)
    obsess_over_service     1   ; We should obsess over this service (if necessary)
    check_freshness         0   ; Default is to NOT check service 'freshness'
    notifications_enabled       1   ; Service notifications are enabled
    event_handler_enabled       1   ; Service event handler is enabled
    flap_detection_enabled      1   ; Flap detection is enabled
    process_perf_data       1   ; Process performance data
    retain_status_information   1   ; Retain status information across program restarts
    retain_nonstatus_information    1   ; Retain non-status information across program restarts

    register            0   ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
    }

5)  the 24x7 time period should be defined

define timeperiod{
    timeperiod_name 24x7
    alias       24 Hours A Day, 7 Days A Week
    sunday      00:00-24:00
    monday      00:00-24:00
    tuesday     00:00-24:00
    wednesday   00:00-24:00
    thursday    00:00-24:00
    friday      00:00-24:00
    saturday    00:00-24:00
    }

6) a contact group is defined
7) the network that is being looked at can be pinged

----------------------------------------------------------------------------------------------------------------------------------------

This check would be installed as multiple commands(one for every subnet) and can then be added as a check to whatever host makes the most sense to have it on(I have it as a check on the Nagios host machine)

For example, if you wanted to check the network 192.168.0.x (let's say your servers) and all you host and service definitions (at least all of them for this subnet) are in the directory /etc/nagios/network and the contact group you are using is "admins" you would need the following:

define command{
    command_name    check_find_new_hosts_servers
    command_line    /usr/lib/nagios/plugins/contrib/check_find_new_hosts -v /etc/nagios/network 192.168.0.0 24 admins
    }

if you also wanted to check 192.168.10.[129-255] (how about these are your domain controllers) with the contact group "domain-admins":

define command{
    command_name    check_find_new_hosts_domain
    command_line    /usr/lib/nagios/plugins/contrib/check_find_new_hosts -v /etc/nagios/network 192.168.10.129 25 domain-admins
    }


You would also need services defined to check these:

define service{
    use         generic-service
    host_name       main-server-router
    service_description FIND_NEW_HOSTS
    is_volatile     0
    check_period        24x7
    max_check_attempts  3
    normal_check_interval   5
    retry_check_interval    1
    contact_groups      admins
    notification_interval   120
    notification_period 24x7
    notification_options    c,r
    check_command       check_find_new_hosts_servers
    }

define service{
    use         generic-service
    host_name       main-domain-controller
    service_description FIND_NEW_HOSTS
    is_volatile     0
    check_period        24x7
    max_check_attempts  3
    normal_check_interval   5
    retry_check_interval    1
    contact_groups      domain-admins
    notification_interval   120
    notification_period 24x7
    notification_options    c,r
    check_command       check_find_new_hosts_domain
    }

----------------------------------------------------------------------------------------------------------------------------------------
once run it may generate the following files (so either run it and generate these files or steer away from them):
x.y.cfg where x.y is from the ip address of the host found: 192.168.15.32 would be put in 15.32.cfg
name.cfg where name is from the fdqn: freddy.mybuddy.com would be put in freddy.cfg
nagios_hostgroup_unknown.cfg (expects this file either to not exist or to contain 1 hostgroup):

define hostgroup {
    hostgroup_name      undefined
    alias           Non-Configured
    members         freddy,betsy,bob,...
    }


use "--nowrite --stdout" ( -xs ) as a command line option to write these to stdout instead of to files if you just want to test it or
use -vvx to show what it is doing but don't write any files and don't show the files on stdout
Related Question