Add multiple groups in Bulk
Add multiple groups in Bulk
I am in the process of creating groups for multiple systems that will be added into nagios and I would like to have host groups in place. There will be a total of 51 groups that I will be adding. Is there a way to add multiple groups instead of one by one?
Re: Add multiple groups in Bulk
The easiest way would be for you to create a file called hostgroups.cfg and put it in /usr/local/nagios/etc/import and then run these commands:
That will import the config file to the CCM and apply configuration.
Here is an example of the layout:
You don't have to define the members (only the hostgroup_name and alias are required), you can see here for other available options you can specify for them:
https://assets.nagios.com/downloads/nag ... #hostgroup
You could also use the API to do this, please go to http://YOURXISERVER/nagiosxi/help/api-c ... -hostgroup for an example.
Let us know if you have any questions.
Code: Select all
cd /usr/local/nagiosxi/scripts
./reconfigure_nagios.shHere is an example of the layout:
Code: Select all
define hostgroup {
hostgroup_name linux-servers
alias Linux Servers
members localhost
}
define hostgroup {
hostgroup_name anotherhostgroup
alias Another Hostgroup
members localhost
}
define hostgroup {
hostgroup_name anotherhostgroup2
alias Another Hostgroup2
}https://assets.nagios.com/downloads/nag ... #hostgroup
You could also use the API to do this, please go to http://YOURXISERVER/nagiosxi/help/api-c ... -hostgroup for an example.
Let us know if you have any questions.
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Add multiple groups in Bulk
To script it through the API you would have to do something like the following
Code: Select all
#!/bin/bash
declare -a hostgroup=("hostgroup 1" "hostgroup 2" "hostgroup 3")
declare -a alias=("hostgroup 1 alias" "hostgroup 2 alias" "hostgroup 3 alias")
num=0
for i in "${hostgroup[@]}"
do
al="${alias[$num]}"
data=`echo "hostgroup_name=$i&alias=$al"`
curl -XPOST "http://YOUR_HOST/nagiosxi/api/v1/config/hostgroup?apikey=YOUR_API_KEY&pretty=1" -d "$data"
num=$((num+1))
done
curl -XPOST "http://YOUR_HOST/nagiosxi/api/v1/system/applyconfig?apikey=YOUR_API_KEY"
Re: Add multiple groups in Bulk
Thank you Scott much appreciate it. We recently upgraded to Nagios 5.5.7 and I attempted to use the Bulk host monitoring wizard to add a set of servers but I am getting a configuration error.
Can I send you a PM?
Can I send you a PM?
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Add multiple groups in Bulk
After consulting with the developers about the cause of this, we did come up with a cause and that is the file format changes slightly in the newer versions and need to be re-written to be parsed correctly.
Lets to the following. Remove the erroneous configs for the host/services, in the CCM.
Then
CCM -> Tools -> Config File Management
Delete Files
Write Configs
Verify Files
Restart Nagios Core
This will reset the configs
Now, the Bulk Host Import Wizard should work correctly.
Lets to the following. Remove the erroneous configs for the host/services, in the CCM.
Then
CCM -> Tools -> Config File Management
Delete Files
Write Configs
Verify Files
Restart Nagios Core
This will reset the configs
Now, the Bulk Host Import Wizard should work correctly.
Re: Add multiple groups in Bulk
Verification gave me an error
Error: Service description, host name, or check command is NULL
Error: Could not register service (config file '/usr/local/nagios/etc/services/<Aservername>.cfg', starting on line 16)
Nagios Core 4.4.2
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2018-08-16
License: GPL
Website: https://www.nagios.org
Reading configuration data...
Read main config file okay...
Error: Service description, host name, or check command is NULL
Error: Could not register service (config file '/usr/local/nagios/etc/services/<Aservername>', starting on line 16)
Error processing object config files!
***> One or more problems was encountered while processing the config files...
Check your configuration file(s) to ensure that they contain valid
directives and data definitions. If you are upgrading from a previous
version of Nagios, you should be aware that some variables/definitions
may have been removed or modified in this version. Make sure to read
the HTML documentation regarding the config files, as well as the
'Whats New' section to find out what has changed.
I replaced the name of the server with <Aservername>
Error: Service description, host name, or check command is NULL
Error: Could not register service (config file '/usr/local/nagios/etc/services/<Aservername>.cfg', starting on line 16)
Nagios Core 4.4.2
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2018-08-16
License: GPL
Website: https://www.nagios.org
Reading configuration data...
Read main config file okay...
Error: Service description, host name, or check command is NULL
Error: Could not register service (config file '/usr/local/nagios/etc/services/<Aservername>', starting on line 16)
Error processing object config files!
***> One or more problems was encountered while processing the config files...
Check your configuration file(s) to ensure that they contain valid
directives and data definitions. If you are upgrading from a previous
version of Nagios, you should be aware that some variables/definitions
may have been removed or modified in this version. Make sure to read
the HTML documentation regarding the config files, as well as the
'Whats New' section to find out what has changed.
I replaced the name of the server with <Aservername>
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Add multiple groups in Bulk
Remove the erroneous configs for the host/services, in the CCM.
Then
CCM -> Tools -> Config File Management
Delete Files
Write Configs
Verify Files
Restart Nagios Core
This will reset the configs
Now, the Bulk Host Import Wizard should work correctly.
Then
CCM -> Tools -> Config File Management
Delete Files
Write Configs
Verify Files
Restart Nagios Core
This will reset the configs
Now, the Bulk Host Import Wizard should work correctly.
Re: Add multiple groups in Bulk
I'll try the wizard in a few. I removed the hosts that were causing the issue using CCM and after applying the Configuration applied successfully page only shows this (see below) and get cut off not sure if that was in part due to the upgrade or something else. Though I am sure that the pre-flight check is fine it would be nice to see the entire output.
Write host configurations ...
Host configuration files successfully written!
Write service configurations ...
Service configuration files successfully written!
Configuration file: hostgroups.cfg successfully written!
Configuration file: servicegroups.cfg successfully written!
Configuration file: hosttemplates.cfg successfully written!
Configuration file: servicetemplates.cfg successfully written!
Configuration file: timeperiods.cfg successfully written!
Configuration file: commands.cfg successfully written!
Configuration file: contacts.cfg successfully written!
Configuration file: contactgroups.cfg successfully written!
Configuration file: contacttemplates.cfg successfully written!
Configuration file: servicedependencies.cfg successfully written!
Configuration file: hostdependencies.cfg successfully written!
Configuration file: serviceescalations.cfg successfully written!
Configuration file: hostescalations.cfg successfully written!
Configuration file: serviceextinfo.cfg successfully written!
Configuration file: hostextinfo.cfg successfully written!
Write host configurations ...
Host configuration files successfully written!
Write service configurations ...
Service configuration files successfully written!
Configuration file: hostgroups.cfg successfully written!
Configuration file: servicegroups.cfg successfully written!
Configuration file: hosttemplates.cfg successfully written!
Configuration file: servicetemplates.cfg successfully written!
Configuration file: timeperiods.cfg successfully written!
Configuration file: commands.cfg successfully written!
Configuration file: contacts.cfg successfully written!
Configuration file: contactgroups.cfg successfully written!
Configuration file: contacttemplates.cfg successfully written!
Configuration file: servicedependencies.cfg successfully written!
Configuration file: hostdependencies.cfg successfully written!
Configuration file: serviceescalations.cfg successfully written!
Configuration file: hostescalations.cfg successfully written!
Configuration file: serviceextinfo.cfg successfully written!
Configuration file: hostextinfo.cfg successfully written!
-
scottwilkerson
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Add multiple groups in Bulk
In the web UI you have to click verify to see the whole output.
Let us know if you have problems with the bulk wizard after running this procedure
Let us know if you have problems with the bulk wizard after running this procedure
Re: Add multiple groups in Bulk
The bulk modification wizard works now
I tried the import via the command line and it seemed to have worked. Any idea what the php warning might be about?
./reconfigure_nagios.sh
--- reset_config_perms.sh ------------
> Setting CCM script permissions
> Setting script permissions
> Setting special component script permissions
> Setting configuration file/directory permissions
> Setting perfdata directory and RRD permissions
> Setting NOM checkpoint user:group permissions
> + Setting Nagios Core corelog.newobjects user:group permissions
> + Setting CCM configuration file user:group permissions
> + Setting Recurring Downtime file user:group permissions
> + Setting BPI configuration file user:group permissions
--------------------------------------
--- ccm_import.php -------------------
> Setting import directory: /usr/local/nagios/etc/import/
> Importing config files into the CCM
- Importing: /usr/local/nagios/etc/import/hostgroups.cfg .. PHP Warning: Invalid argument supplied for foreach() in /usr/local/nagiosxi/html/includes/components/nagiosim/nagiosim.inc.php on line 491
SUCCESS
--------------------------------------
--- ccm_export.php -------------------
> Writing CCM configuration to Nagios files
PHP Warning: Invalid argument supplied for foreach() in /usr/local/nagiosxi/html/includes/components/nagiosim/nagiosim.inc.php on line 491
Finished writing out configuraton
--------------------------------------
--------------------------------------
> Verifying configuration with Nagios Core
> Output:
Nagios Core 4.4.2
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2018-08-16
License: GPL
Website: https://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...
Checked 18345 services.
Checked 2279 hosts.
Checked 352 host groups.
Checked 17 service groups.
Checked 310 contacts.
Checked 61 contact groups.
Checked 186 commands.
Checked 255 time periods.
Checked 995 host escalations.
Checked 118 service escalations.
Checking for circular paths...
Checked 2279 hosts
Checked 56 service dependencies
Checked 0 host dependencies
Checked 255 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
> Return Code: 0
--------------------------------------
Stopping nagios: .done.
Starting nagios: done.
Line 491 has
{
global $cfg;
if ($cfg['db_info']['nagiosxi']['dbtype'] == 'pgsql') {
$sql = "SELECT COUNT(relname) FROM pg_class WHERE relname = 'xi_incidents'";
$rs = exec_sql_query(DB_NAGIOSXI, $sql, true);
foreach ($rs as $row) {
if ($row['count'] == 0) {
// Create sequence
$sql = "
CREATE SEQUENCE xi_incidents_id_seq
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1";
exec_sql_query(DB_NAGIOSXI, $sql, true);
// Create table
$sql = "
CREATE TABLE IF NOT EXISTS xi_incidents (
id integer DEFAULT nextval('xi_incidents_id_seq'::regclass) NOT NULL,
incident_id integer DEFAULT 0,
submitted integer DEFAULT 0,
type varchar(16),
host varchar(96),
service varchar(96),
event_time timestamp without time zone NOT NULL,
status varchar(16),
output text
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
exec_sql_query(DB_NAGIOSXI, $sql, true);
// Make sure we have access
$sql = "ALTER TABLE public.xi_incidents OWNER TO nagiosxi";
}
}
I tried the import via the command line and it seemed to have worked. Any idea what the php warning might be about?
./reconfigure_nagios.sh
--- reset_config_perms.sh ------------
> Setting CCM script permissions
> Setting script permissions
> Setting special component script permissions
> Setting configuration file/directory permissions
> Setting perfdata directory and RRD permissions
> Setting NOM checkpoint user:group permissions
> + Setting Nagios Core corelog.newobjects user:group permissions
> + Setting CCM configuration file user:group permissions
> + Setting Recurring Downtime file user:group permissions
> + Setting BPI configuration file user:group permissions
--------------------------------------
--- ccm_import.php -------------------
> Setting import directory: /usr/local/nagios/etc/import/
> Importing config files into the CCM
- Importing: /usr/local/nagios/etc/import/hostgroups.cfg .. PHP Warning: Invalid argument supplied for foreach() in /usr/local/nagiosxi/html/includes/components/nagiosim/nagiosim.inc.php on line 491
SUCCESS
--------------------------------------
--- ccm_export.php -------------------
> Writing CCM configuration to Nagios files
PHP Warning: Invalid argument supplied for foreach() in /usr/local/nagiosxi/html/includes/components/nagiosim/nagiosim.inc.php on line 491
Finished writing out configuraton
--------------------------------------
--------------------------------------
> Verifying configuration with Nagios Core
> Output:
Nagios Core 4.4.2
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2018-08-16
License: GPL
Website: https://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...
Checked 18345 services.
Checked 2279 hosts.
Checked 352 host groups.
Checked 17 service groups.
Checked 310 contacts.
Checked 61 contact groups.
Checked 186 commands.
Checked 255 time periods.
Checked 995 host escalations.
Checked 118 service escalations.
Checking for circular paths...
Checked 2279 hosts
Checked 56 service dependencies
Checked 0 host dependencies
Checked 255 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
> Return Code: 0
--------------------------------------
Stopping nagios: .done.
Starting nagios: done.
Line 491 has
{
global $cfg;
if ($cfg['db_info']['nagiosxi']['dbtype'] == 'pgsql') {
$sql = "SELECT COUNT(relname) FROM pg_class WHERE relname = 'xi_incidents'";
$rs = exec_sql_query(DB_NAGIOSXI, $sql, true);
foreach ($rs as $row) {
if ($row['count'] == 0) {
// Create sequence
$sql = "
CREATE SEQUENCE xi_incidents_id_seq
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1";
exec_sql_query(DB_NAGIOSXI, $sql, true);
// Create table
$sql = "
CREATE TABLE IF NOT EXISTS xi_incidents (
id integer DEFAULT nextval('xi_incidents_id_seq'::regclass) NOT NULL,
incident_id integer DEFAULT 0,
submitted integer DEFAULT 0,
type varchar(16),
host varchar(96),
service varchar(96),
event_time timestamp without time zone NOT NULL,
status varchar(16),
output text
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";
exec_sql_query(DB_NAGIOSXI, $sql, true);
// Make sure we have access
$sql = "ALTER TABLE public.xi_incidents OWNER TO nagiosxi";
}
}