Page 3 of 4

Re: Bulk Clone from Command line

Posted: Wed Jun 10, 2015 12:06 pm
by peter.zanetti
Removing the spaces did not seem to fix the issue. I ran it in the debug mode and have pasted the output below.

Code: Select all

[root@esu2v236 scripts]# bash -x cfg-generator.sh
+ /bin/cat /usr/local/nagiosxi/scripts/new-hosts.csv
+ read LINE
+ cd /usr/local/nagiosxi/scripts
+ ./reconfigure_nagios.sh
URL: http://localhost/nagiosxi/includes/components/ccm/
CMDLINE
/usr/bin/wget --save-cookies nagiosql.cookies --keep-session-cookies http://localhost/nagiosxi/includes/components/ccm/ --no-check-certificate --post-data 'submit=Login&hidelog=true&loginSubmitted=true&username=nagiosxi&password=n@gweb' -O nagiosql.login--2015-06-10 13:04:23--  http://localhost/nagiosxi/includes/components/ccm/
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: “nagiosql.login”

    [ <=>                                                                                                                                                        ] 10,379      --.-K/s   in 0.008s

2015-06-10 13:04:23 (1.23 MB/s) - “nagiosql.login” saved [10379]

LOGIN SUCCESSFUL!
IMPORTING CONFIG FILES...URL: http://localhost/nagiosxi/includes/components/ccm/
Array
(
)
SETUID ROOT OK
RESETTING PERMS
URL: http://localhost/nagiosxi/includes/components/ccm/
CMDLINE
/usr/bin/wget --save-cookies nagiosql.cookies --keep-session-cookies http://localhost/nagiosxi/includes/components/ccm/ --no-check-certificate --post-data 'submit=Login&hidelog=true&loginSubmitted=true&username=nagiosxi&password=n@gweb' -O nagiosql.login--2015-06-10 13:04:23--  http://localhost/nagiosxi/includes/components/ccm/
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: “nagiosql.login”

    [ <=>                                                                                                                                                        ] 10,379      --.-K/s   in 0.008s

2015-06-10 13:04:24 (1.21 MB/s) - “nagiosql.login” saved [10379]

LOGIN SUCCESSFUL!
URL: http://localhost/nagiosxi/includes/components/ccm/
CMDLINE:
/usr/bin/wget --load-cookies=nagiosql.cookies http://localhost/nagiosxi/includes/components/ccm/ --no-check-certificate --post-data 'cmd=apply&type=writeConfig' -O nagiosql.export.monitoring
--2015-06-10 13:04:24--  http://localhost/nagiosxi/includes/components/ccm/
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: “nagiosql.export.monitoring”

    [  <=>                                                                                                                                                       ] 13,233      44.7K/s   in 0.3s

2015-06-10 13:04:24 (44.7 KB/s) - “nagiosql.export.monitoring” saved [13233]

WRITE CONFIGS SUCCESSFUL!
OUTPUT:
Nagios Core 4.0.8
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-12-2014
License: GPL

Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
Warning: Service 'DisplayAuditWCF.svc' on host 'BL001ASRET01' has no default contacts or contactgroups defined!
        Checked 19 services.
Warning: Host 'BL001ASRET01' has no default contacts or contactgroups defined!
        Checked 4 hosts.
        Checked 4 host groups.
        Checked 0 service groups.
        Checked 10 contacts.
        Checked 2 contact groups.
        Checked 119 commands.
        Checked 16 time periods.
        Checked 0 host escalations.
        Checked 0 service escalations.
Checking for circular paths...
        Checked 4 hosts
        Checked 0 service dependencies
        Checked 0 host dependencies
        Checked 16 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 2
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check
RET: 0
Running configuration check...
Stopping nagios: done.
Starting nagios: done.
[root@esu2v236 scripts]#

Re: Bulk Clone from Command line

Posted: Wed Jun 10, 2015 12:21 pm
by abrist
Can you post the following file (in code wraps) after attempting an automated import:

Code: Select all

/usr/local/nagiosxi/scripts/nagiosql.import.monitoring

Re: Bulk Clone from Command line

Posted: Wed Jun 10, 2015 12:28 pm
by peter.zanetti
I'm having trouble adding it. It says the extension monitoring is not allowed.

Re: Bulk Clone from Command line

Posted: Wed Jun 10, 2015 12:29 pm
by peter.zanetti
Threw it into a notepad document and then copied it instead of trying to just attach the file.

Code: Select all

        <!DOCTYPE html>
        <!-- Produced by Nagios XI. Copyright (c) 2008-2015 Nagios Enterprises, LLC (www.nagios.com). All Rights Reserved. -->
        <!-- Powered by the Nagios Synthesis Framework -->

        <html>

    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
                <title>Nagios XI - Nagios Core Config Manager</title>
        <meta name="ROBOTS" content="NOINDEX, NOFOLLOW">
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>


            <link rel="shortcut icon" href="http://localhost/nagiosxi/images/favicon.ico" type="image/ico"/>
    <link rel='stylesheet' type='text/css' href='http://localhost/nagiosxi/includes/css/jquery.autocomplete.css'/>

    <script type='text/javascript'>
        //javascript:alert(document.documentMode);

        var base_url = "http://localhost/nagiosxi/";
        var backend_url = "http%3A%2F%2Flocalhost%2Fnagiosxi%2Fincludes%2Fcomponents%2Fccm%2Findex.php";
        var ajax_helper_url = "http://localhost/nagiosxi/ajaxhelper.php";
        var ajax_proxy_url = "http://localhost/nagiosxi/ajaxproxy.php";
        var suggest_url = "http://localhost/nagiosxi/suggest.php";
        var request_uri = "%2Fnagiosxi%2Fincludes%2Fcomponents%2Fccm%2F";
        var permalink_base = "http://localhost/nagiosxi/includes/components/ccm/?&cmd=admin&type=import&importsubmitted=true&chbOverwrite=1&selImportFile=a%3A1%3A%7Bi%3A0%3Bs%3A45%3A%22%2Fusr%2Flocal%2Fnagios%2Fetc%2Fimport%2Fjs70o2rp.tmp.cfg%22%3B%7D";
        var demo_mode =0;
        var nsp_str = "1e609664336cb2a858173499f41c0160";
    </script>

            <!-- Bootstrap for 2014 UI -->
        <link rel="stylesheet" href="http://localhost/nagiosxi/includes/css/bootstrap.min.css?2014R2.7" type="text/css" />
    
    <!-- Adding Font-Awesome for all themes -->
    <link rel="stylesheet" href="http://localhost/nagiosxi/includes/css/font-awesome.min.css?2014R2.7" type="text/css" />

    <!-- main jquery libraries -->
    <script type='text/javascript' src='http://localhost/nagiosxi/includes/js/jquery/jquery-1.8.2.min.js?2014R2.7'></script>
    <link type="text/css" href="http://localhost/nagiosxi/includes/js/jquery/css/smoothness/jquery-ui-1.9.0.custom.min.css?2014R2.7" rel="stylesheet"/>
    <script type='text/javascript' src='http://localhost/nagiosxi/includes/js/jquery/jquery.colorBlend.js'></script>
    <script type='text/javascript' src='http://localhost/nagiosxi/includes/js/jquery/jquery.timers-1.1.3.js'></script>
    <script type='text/javascript' src='http://localhost/nagiosxi/includes/js/jquery/jquery-ui-1.9.0.custom.min.js?2014R2.7'></script>
    <script type='text/javascript' src='http://localhost/nagiosxi/includes/js/jquery/jquery.searchabledropdown.custom.js'></script>

    <!-- colorpicker -->
    <link rel="stylesheet" href="http://localhost/nagiosxi/includes/js/jquery/colorpicker/css/colorpicker.css" type="text/css" />
    <script type="text/javascript" src="http://localhost/nagiosxi/includes/js/jquery/colorpicker/js/colorpicker.js"></script>

    <!-- clipboard plugin -->
    <script type="text/javascript" src="http://localhost/nagiosxi/includes/js/jquery/jquery.zclip.min.js"></script>

    <!-- XI JS Scripts -->
        <script type='text/javascript' src='http://localhost/nagiosxi/includes/js/core_2014.js?2014R2.7'></script>
        <script type='text/javascript' src='http://localhost/nagiosxi/includes/js/commands.js?2014R2.7'></script>
    <script type='text/javascript' src='http://localhost/nagiosxi/includes/js/views.js?2014R2.7'></script>
    <script type='text/javascript' src='http://localhost/nagiosxi/includes/js/dashboards.js?2014R2.7'></script>
    <script type='text/javascript' src='http://localhost/nagiosxi/includes/js/dashlets.js?2014R2.7'></script>
    <script type='text/javascript' src='http://localhost/nagiosxi/includes/js/tables.js?2014R2.7'></script>
    <script type='text/javascript' src='http://localhost/nagiosxi/includes/js/users.js?2014R2.7'></script>
    <script type='text/javascript' src='http://localhost/nagiosxi/includes/js/perfdata.js?2014R2.7'></script>
    <script type='text/javascript' src='http://localhost/nagiosxi/includes/js/wizards.js?2014R2.7'></script>

    <!-- XI CSS -->
        <link rel='stylesheet' type='text/css' href='http://localhost/nagiosxi/includes/css/nagiosxi_2014.css?2014R2.7' />
    
    <!-- Highcharts Graphing Library -->
    <script type="text/javascript" src="http://localhost/nagiosxi//includes/js/highcharts/highcharts.js?416"></script>
            <script type="text/javascript" src="http://localhost/nagiosxi//includes/js/highcharts/highcharts-more.js?416"></script>
            <script type="text/javascript" src="http://localhost/nagiosxi//includes/js/highcharts/modules/exporting.js?416"></script>
    <!-- D3 Graphing Library -->
    <script type='text/javascript' src='http://localhost/nagiosxi/includes/js/d3/d3.v3.min.js?2014R2.7'></script>

    <script type='text/javascript' src='http://localhost/nagiosxi/includes/dashlets/gauges/js/gauge.js'></script>
<link rel='stylesheet' type='text/css' href='http://localhost/nagiosxi/includes/dashlets/internethealthreport/internethealthreport.css' />
<link rel='stylesheet' type='text/css' href='http://localhost/nagiosxi/includes/dashlets/internettrafficreport/internettrafficreport.css' />
<link rel='stylesheet' type='text/css' href='http://localhost/nagiosxi/includes/dashlets/rss_dashlet/rss_dashlet.css' />
<link rel='stylesheet' type='text/css' href='http://localhost/nagiosxi/includes/dashlets/sansrisingports/sansrisingports.css' />
<link rel='stylesheet' type='text/css' href='http://localhost/nagiosxi/includes/dashlets/worldtimeserver/worldtimeserver.css' />
                <link rel='stylesheet' type='text/css' href='http://localhost/nagiosxi/includes/components/ccm/css/style.css?2.3.3' /><script type="text/javascript" src="http://localhost/nagiosxi/includes/components/ccm/javascript/main_js.js?2.3.3"></script>
          <script type="text/javascript">
          var NAGIOSXI=true
          </script><script type="text/javascript" src="http://localhost/nagiosxi/includes/components/graphexplorer/includes/graphexplorerinclude.js"></script><script type='text/javascript' src='http://localhost/nagiosxi/includes/components/helpsystem/helpsysteminclude.js?0.5'></script><link rel='stylesheet' type='text/css' href='http://localhost/nagiosxi/includes/components/helpsystem/helpsystem.css?0.5' />    </head>


    <body  class=' child' >

    
    <div  class="childpage"><!-- page-->

    <div id ="childheader" class="childhead" >
        
<!--- CHILD HEADER START -->

<div id="child_popup_layer">
    <div id="child_popup_content">
        <div id="child_popup_close">
            <a id="close_child_popup_link" style="display: inline-block;" title="Close"><i class="fa fa-times" style="font-size: 16px;"></i></a>
        </div>
        <div id="child_popup_container">
        </div>
    </div>
</div>

<!--- CHILD HEADER END -->    </div><!--header -->


            <div id="childcontentthrobber"><img src='http://localhost/nagiosxi/images/throbber1.gif'/></div>
        <div id="screen-overlay"></div>
    <div id="loginMsgDiv" style="display: none;">
        <span class='deselect'>
            <div >
                Logged in as: nagiosxi <a href='index.php?cmd=logout'>Logout</a>            </div>
        </span>
    </div>
<div id='mainNavMenu'><a href='index.php?cmd=view&type=host'>Hosts</a><br /><a href='index.php?cmd=view&type=service'>Services<br /><a href='index.php?cmd=view&type=hostgroup'>Host Groups</a><br /><a href='index.php?cmd=view&type=servicegroup'>Service Groups</a><br /><a href='index.php?cmd=view&type=hosttemplate'>Host Templates</a><br /><a href='index.php?cmd=view&type=servicetemplate'>Service Templates</a><br /><a href='index.php?cmd=view&type=contact'>Contacts</a><br /><a href='index.php?cmd=view&type=contactgroup'>Contact Groups</a><br /><a href='index.php?cmd=view&type=contacttemplate'>Contact Templates</a><br /><a href='index.php?cmd=view&type=timeperiod'>Timeperiods</a><br /><a href='index.php?cmd=view&type=command'>Commands</a><br /><a href='index.php?cmd=view&type=hostescalation'>Host Escalations</a><br /><a href='index.php?cmd=view&type=serviceescalation'>Service Escalations</a><br /><a href='index.php?cmd=view&type=hostdependency'>Host Dependencies</a><br /><a href='index.php?cmd=view&type=servicedependency'>Service Dependencies</a><br /><br /><a href='index.php?cmd=admin&type=static'>Static Configurations</a><br /><a href='index.php?cmd=admin&type=import'>Import Configs</a><br /><a href='index.php?cmd=apply'>Write Configs</a><br /><a href='index.php?cmd=admin&type=corecfg'>Nagios Main Config</a><br /><a href='index.php?cmd=admin&type=cgicfg'>Nagios CGI Config</a><br /><br /><a href='index.php?cmd=admin&type=user'>Manage CCM Users</a><br /><a href='index.php?cmd=admin&type=log'>CCM Log</a><br /><a href='index.php?cmd=admin&type=settings'>CCM Settings</a><br /></div>    <div id='contentWrapper' style="width: 100%;">
        <form action='index.php' method='post' id='formInput' name='frmInput'>

            <h1 style="margin-bottom: 10px;">Configuration Import</h1>
            <input type="text" style="width:120px" value="" name="txtSearch" id='txtSearch' placeholder="Search..." />
            <img width="18" height="18" style="cursor: hand; cursor:pointer;" onclick="document.forms[0].submit()" title="Search" alt="Search" src="/nagiosql/images/lupe.gif" />
            <img width="18" height="18" style="cursor: hand; cursor:pointer;" onclick="$('#txtSearch').val('');document.forms[0].submit();" title="Delete" alt="Delete" src="/nagiosql/images/del.png">
            <br style="clear: both;" />
    
            <div id='returnContent' class='success' style="margin-bottom: 15px;">1 file(s) imported successfully!<br></div>
                <select id="selImportFile" multiple="multiple" size="10" style='width:80%;' name="selImportFile[]">
                <option value='/usr/local/nagios/etc/commands.cfg'>/usr/local/nagios/etc/commands.cfg</option><option value='/usr/local/nagios/etc/contactgroups.cfg'>/usr/local/nagios/etc/contactgroups.cfg</option><option value='/usr/local/nagios/etc/contacts.cfg'>/usr/local/nagios/etc/contacts.cfg</option><option value='/usr/local/nagios/etc/contacttemplates.cfg'>/usr/local/nagios/etc/contacttemplates.cfg</option><option value='/usr/local/nagios/etc/hostdependencies.cfg'>/usr/local/nagios/etc/hostdependencies.cfg</option><option value='/usr/local/nagios/etc/hostescalations.cfg'>/usr/local/nagios/etc/hostescalations.cfg</option><option value='/usr/local/nagios/etc/hostextinfo.cfg'>/usr/local/nagios/etc/hostextinfo.cfg</option><option value='/usr/local/nagios/etc/hostgroups.cfg'>/usr/local/nagios/etc/hostgroups.cfg</option><option value='/usr/local/nagios/etc/hosts/K4534142.cfg'>/usr/local/nagios/etc/hosts/K4534142.cfg</option><option value='/usr/local/nagios/etc/hosts/K4582367.cfg'>/usr/local/nagios/etc/hosts/K4582367.cfg</option><option value='/usr/local/nagios/etc/hosts/localhost.cfg'>/usr/local/nagios/etc/hosts/localhost.cfg</option><option value='/usr/local/nagios/etc/hosttemplates.cfg'>/usr/local/nagios/etc/hosttemplates.cfg</option><option value='/usr/local/nagios/etc/import/js70o2rp.tmp.cfg'>/usr/local/nagios/etc/import/js70o2rp.tmp.cfg</option><option value='/usr/local/nagios/etc/servicedependencies.cfg'>/usr/local/nagios/etc/servicedependencies.cfg</option><option value='/usr/local/nagios/etc/serviceescalations.cfg'>/usr/local/nagios/etc/serviceescalations.cfg</option><option value='/usr/local/nagios/etc/serviceextinfo.cfg'>/usr/local/nagios/etc/serviceextinfo.cfg</option><option value='/usr/local/nagios/etc/servicegroups.cfg'>/usr/local/nagios/etc/servicegroups.cfg</option><option value='/usr/local/nagios/etc/services/K4534142.cfg'>/usr/local/nagios/etc/services/K4534142.cfg</option><option value='/usr/local/nagios/etc/services/K4582367.cfg'>/usr/local/nagios/etc/services/K4582367.cfg</option><option value='/usr/local/nagios/etc/services/localhost.cfg'>/usr/local/nagios/etc/services/localhost.cfg</option><option value='/usr/local/nagios/etc/servicetemplates.cfg'>/usr/local/nagios/etc/servicetemplates.cfg</option><option value='/usr/local/nagios/etc/timeperiods.cfg'>/usr/local/nagios/etc/timeperiods.cfg</option>                </select>
                <div>
                    <label style="line-height: 30px;" for='chbOverwrite'>Overwrite Database                    <input type="checkbox" checked="checked" value="1" id="chbOverwrite" class="checkbox" name="chbOverwrite" style="vertical-align: middle;" /></label>
                </div>
                <p>To prevent errors or misconfigurations, you should import your configurations in an useful order. We recommend importing in the following order:</p>
                <p>
                    <strong><em>commands -> timeperiods -> contacttemplates -> contacts -> contactgroups -> <br />
                    hosttemplates -> hosts -> hostgroups -> servicetemplates -> services -> servicegroups</em></strong>
                </p>
                <p><em>The CCM import tool does not currently support object names that start with '#', or group exclusions that start with '!'</em><br /></p>
                <p><strong>Check your configurations after import before saving to file!</strong></p>
            </div>
    
            <input type="submit" class='ccmButton' value="Import" id="subForm" name="subForm" />
            <input type="button" class='ccmButton' value="Abort" id="abort" name="abort" onclick="document.forms[0].reset();"/>
            <input type="hidden" value="true" id="importsubmitted" name="importsubmitted" />
            <input type='hidden' name='cmd' value='admin' />
            <input type='hidden' name='type' value='import' />
        
        </form>
    </div>

    
    <!-- CHILD FOOTER START -->


<!-- CHILD FOOTER END -->
    </div><!--page-->

    <noframes>
        <!-- This page requires a web browser which supports frames. -->
        <h2>Nagios XI</h2>
        <p align="center">
            <a href="http://www.nagios.com/">www.nagios.com</a><br>
            Copyright (c) 2009-2012 Nagios Enterprises, LLC<br>
        </p>
        <p>
            <i>Note: These pages require a browser which supports frames</i>
        </p>
    </noframes>

    
    
    </body>
</html>


Re: Bulk Clone from Command line

Posted: Wed Jun 10, 2015 12:44 pm
by lmiltchev
So we got all the files in the /usr/local/nagiosxi/scripts folder, made the script executable, and tried to execute the command.
Let's make sure, you have all of the three files in the scripts directory and the "new-hosts.csv" is not empty. Also, let's check the path to the "echo" and "cut" commands.

Code: Select all

ll /usr/local/nagiosxi/scripts | grep "base-template.cfg\|cfg-generator.sh\|new-hosts.csv"
cat /usr/local/nagiosxi/scripts/new-hosts.csv
which echo
which cut
Note: Make sure that the "new-hosts.csv" has unix EOL (not dos).

It seems like your "new-hosts.csv" is empty or "echo" & "cut" could not be run... You are missing some commands in the output... Here's what I get, when I run the script:

Code: Select all

[root@testbox scripts]# bash -x cfg-generator.sh
+ /bin/cat /usr/local/nagiosxi/scripts/new-hosts.csv
+ read LINE
++ /bin/echo K4283696, K4283696, Test, linux-servers
++ /bin/cut -d, -f1
+ Name=K4283696
++ /bin/echo K4283696, K4283696, Test, linux-servers
++ /bin/cut -d, -f2
+ Address=' K4283696'
++ /bin/echo K4283696, K4283696, Test, linux-servers
++ /bin/cut -d, -f3
+ Description=' Test'
++ /bin/echo K4283696, K4283696, Test, linux-servers
++ /bin/cut -d, -f4
+ Hostgroup=' linux-servers'
+ sed -e 's/AAAA/K4283696/g; s/BBBB/ K4283696/g; s/CCCC/ Test/g; s/DDDD/ linux-servers/g' /usr/local/nagiosxi/scripts/base-template.cfg
+ read LINE
+ cd /usr/local/nagiosxi/scripts
+ ./reconfigure_nagios.sh
.......................................

Re: Bulk Clone from Command line

Posted: Wed Jun 10, 2015 12:48 pm
by peter.zanetti
Here is the output from those commands. Also, what is Unix EOL?

Code: Select all

[root@esu2v236 tmp]# ll /usr/local/nagiosxi/scripts | grep "base-template.cfg\|cfg-generator.sh\|new-hosts.csv"
-rw-r--r-- 1 b002908 fsg       289 Jun  5 09:49 base-template.cfg
-rwxr-xr-x 1 b002908 fsg       542 Jun 10 08:59 cfg-generator.sh
-rw-r--r-- 1 b002908 fsg        36 Jun 10 12:58 new-hosts.csv
[root@esu2v236 tmp]# cat /usr/local/nagiosxi/scripts/new-hosts.csv
K4283696,K4283696,Test,LabDISDevices[root@esu2v236 tmp]# which echo
/bin/echo
[root@esu2v236 tmp]# which cut
/bin/cut

Re: Bulk Clone from Command line

Posted: Wed Jun 10, 2015 1:05 pm
by lmiltchev
Also, what is Unix EOL?
These are line endings. You can read more about EOL here:
http://www.cs.toronto.edu/~krueger/csc2 ... dings.html

When you open your file in the "vi" text editor, you can type:

Code: Select all

:set ff?
and hit "Enter". This will show you the format. To set the format to "unix", type:

Code: Select all

:set ff=unix
and hit enter.

Re: Bulk Clone from Command line

Posted: Wed Jun 10, 2015 1:26 pm
by peter.zanetti
The file format was set to unix already. But I did set it again just to be sure.

Re: Bulk Clone from Command line

Posted: Wed Jun 10, 2015 2:04 pm
by ssax
For whatever reason you new-hosts.csv file doesn't have a line ending on that line.

On the linux system, edit the new-hosts.csv file, and a new empty line at the end and save it, then try it.

Edit:

Or you can just run this command:

Code: Select all

sed -i -e '$a\' yourcsvfile

Re: Bulk Clone from Command line

Posted: Wed Jun 10, 2015 2:49 pm
by peter.zanetti
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?