Bulk Clone from Command line

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
peter.zanetti
Posts: 90
Joined: Wed Oct 01, 2014 8:34 am

Re: Bulk Clone from Command line

Post by peter.zanetti »

peter.zanetti wrote:That was the issue. I figured it out right about the same time you posted back.

Now to throw another curveball in this, if we wanted to add a device but give it two host groups, is that possible?
Would it be as easy as adding a set of E's on the template, adding a fifth value in the CSV and adding one more hostgroup echo and cut and throwing the argument in the sed such as:

Code: Select all

# Original (base) template

define host{
        use                     xiwizard_windowsdesktop_host
        host_name               AAAA
        address                 BBBB
        alias                   CCCC
        hostgroups                              DDDD,EEEE
        }

Code: Select all

#!/bin/bash

/bin/cat  /usr/local/nagiosxi/scripts/new-hosts.csv | while read LINE
do
        Name=`/bin/echo $LINE | /bin/cut -d, -f1`
        Address=`/bin/echo $LINE | /bin/cut -d, -f2`
        Description=`/bin/echo $LINE | /bin/cut -d, -f3`
        Hostgroup1=`/bin/echo $LINE | /bin/cut -d, -f4`
        Hostgroup2=`/bin/echo $LINE | /bin/cut -d, -f5`
        sed -e "s/AAAA/$Name/g; s/BBBB/$Address/g; s/CCCC/$Description/g; s/DDDD
/$Hostgroup1/g; s/EEEE/$Hostgroup2/g" /usr/local/nagiosxi/scripts/base-template.cfg > /usr/local/nagios
/etc/import/$Name.cfg
done
cd /usr/local/nagiosxi/scripts
./reconfigure_nagios.sh
peter.zanetti
Posts: 90
Joined: Wed Oct 01, 2014 8:34 am

Re: Bulk Clone from Command line

Post by peter.zanetti »

Just tested that and it was successful!
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Bulk Clone from Command line

Post by lmiltchev »

Great! Let us know if it is safe to lock this topic and mark it as resolved.
Be sure to check out our Knowledgebase for helpful articles and solutions!
peter.zanetti
Posts: 90
Joined: Wed Oct 01, 2014 8:34 am

Re: Bulk Clone from Command line

Post by peter.zanetti »

There is one last thing. We set up some custom check commands and intervals on the actual template itself before running the script.
custom host check tmp.PNG
custom check settings tmp.PNG

But when we look at the device the script created both in the home GUI and configure GUI none of the information shows up.
host check host.PNG
Is there a reason for this? Is there a way to fix this?
You do not have the required permissions to view the files attached to this post.
Last edited by peter.zanetti on Thu Jun 11, 2015 12:48 pm, edited 1 time in total.
peter.zanetti
Posts: 90
Joined: Wed Oct 01, 2014 8:34 am

Re: Bulk Clone from Command line

Post by peter.zanetti »

second screenshot for the host settings, wouldn't let me post more than three.
You do not have the required permissions to view the files attached to this post.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Bulk Clone from Command line

Post by lmiltchev »

These values should be inherited from the template. Open the "/usr/local/nagios/var/objects.cache" in a text editor, find the "K4283696" host and see what is the actual check_command that is used.
Be sure to check out our Knowledgebase for helpful articles and solutions!
peter.zanetti
Posts: 90
Joined: Wed Oct 01, 2014 8:34 am

Re: Bulk Clone from Command line

Post by peter.zanetti »

This is what that got me. It doesnt look like it inherited the right check command or check intervals.

Code: Select all

define service {
        host_name       K4283696
        service_description     DisplayAuditWCF.svc
        check_period    workhours
        check_command   check_xi_service_http! -f ok -I $HOSTADDRESS$ -u '/Displ
ayAuditWCF.svc?singleWsdl' -p 35002!!!!!!!
        notification_period     xi_timeperiod_24x7
        initial_state   o
        importance      0
        check_interval  15.000000
        retry_interval  2.000000
        max_check_attempts      3
        is_volatile     0
        parallelize_check       1
        active_checks_enabled   1
        passive_checks_enabled  1
        obsess  1
        event_handler_enabled   1
        low_flap_threshold      0.000000
        high_flap_threshold     0.000000
        flap_detection_enabled  1
        flap_detection_options  a
        freshness_threshold     0
        check_freshness 0
        notification_options    a
        notifications_enabled   1
        notification_interval   60.000000
        first_notification_delay        0.000000
        stalking_options        n
        process_perf_data       1
        retain_status_information       1
        retain_nonstatus_information    1
        }
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Bulk Clone from Command line

Post by lmiltchev »

Can you upload the actual base template that you are using? In the template you uploaded earlier, you didn't have a service defined at all...

Code: Select all

# Original (base) template

define host{
        use                     xiwizard_windowsdesktop_host
        host_name               AAAA
        address                 BBBB
        alias                   CCCC
        hostgroups                              DDDD
        }
If you modified the "xiwizard_windowsdesktop_host" template, the mods will be applied to the host, not to the service as this is a host template. If you had a service in your "base" template, for example:

Code: Select all

    # Original (base) template

    define host{
            use                     xiwizard_generic_host
            host_name               AAAA
            address                 BBBB
            alias                   CCCC
            hostgroups                              DDDD
            }


    define service{
            use                             xiwizard_generic_service
            host_name                       AAAA
            service_description             DisplayAuditWCF.svc
            }
and you wanted to modify the check command this service is using, you would need to modify the "xiwizard_generic_service" template.

Note: This is a service, not host template.

What you showed us in your previous post is a service definition:
define service {
host_name K4283696
service_description DisplayAuditWCF.svc
check_period workhours
The host template changes won't apply to the service...
Be sure to check out our Knowledgebase for helpful articles and solutions!
peter.zanetti
Posts: 90
Joined: Wed Oct 01, 2014 8:34 am

Re: Bulk Clone from Command line

Post by peter.zanetti »

We figured out a solution. On the template we manually have the service and intervals defined while leaving the other fields be fed by the CSV and script.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Bulk Clone from Command line

Post by lmiltchev »

Sounds good! I will be locking this topic how. If you have any more questions, please start a new thread.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked