Nagios 配置错误:飞行前检查期间出现“文件中出现意外的令牌或语句”

Nagios 配置错误:飞行前检查期间出现“文件中出现意外的令牌或语句”

我在 CentOS 6.5 上使用 Nagios 3.2.3。一切进行install得很make顺利。我转移了我的配置文件,做了适当的更改,并对我的 nagios.cfg 文件进行了飞行前测试。在我的 nagios.cfg 文件中,我使用cfg_dir=/usr/local/nagios/etc/conf.d然后让 Nagios 递归搜索该目录。

输出/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg显示以下内容:

Website: http://www.nagios.org
Reading configuration data...
    Read main config file okay...
Processing object config directory '/usr/local/nagios/etc/conf.d'...
Processing object config directory '/usr/local/nagios/etc/conf.d/hostgroups.d'...
Processing object config file '/usr/local/nagios/etc/conf.d/hostgroups.d/hostgroups.cfg'...
Processing object config directory '/usr/local/nagios/etc/conf.d/commands.d'...
Processing object config file '/usr/local/nagios/etc/conf.d/commands.d/commands.cfg'...
Processing object config directory '/usr/local/nagios/etc/conf.d/templates.d'...
Processing object config file '/usr/local/nagios/etc/conf.d/templates.d/templates.cfg'...
Processing object config file '/usr/local/nagios/etc/conf.d/templates.d/printer.cfg'...
Processing object config file '/usr/local/nagios/etc/conf.d/templates.d/switch.cfg'...
Processing object config file '/usr/local/nagios/etc/conf.d/templates.d/timeperiods.cfg'...
Processing object config file '/usr/local/nagios/etc/conf.d/templates.d/windows.cfg'...
Processing object config directory '/usr/local/nagios/etc/conf.d/objects'...
Processing object config file '/usr/local/nagios/etc/conf.d/objects/previews-indexes-qa.cfg'...
Processing object config file '/usr/local/nagios/etc/conf.d/objects/contacts.cfg'...
Processing object config file '/usr/local/nagios/etc/conf.d/objects/restart_cb_sites.cfg'...
Processing object config file '/usr/local/nagios/etc/conf.d/objects/hudson-slave01.cfg'...
Processing object config file '/usr/local/nagios/etc/conf.d/objects/ipc-qa.cfg'...
Processing object config file '/usr/local/nagios/etc/conf.d/objects/russellreynolds.cfg'...
Processing object config file '/usr/local/nagios/etc/conf.d/objects/lr.cfg'...
Processing object config file '/usr/local/nagios/etc/conf.d/objects/ts-01.cfg'...
Processing object config file '/usr/local/nagios/etc/conf.d/cgi.cfg'...
Error: Unexpected token or statement in file '/usr/local/nagios/etc/conf.d/cgi.cfg' on line 15.
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 defintions.  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.

因此我检查cgi.cfg文件的第 15 行,它指向我的main_config_file=

#################################################################
#
# CGI.CFG - Sample CGI Configuration File for Nagios 3.4.4
#
# Last Modified: 06-17-2009
#
#################################################################


# MAIN CONFIGURATION FILE
# This tells the CGIs where to find your main configuration file.
# The CGIs will read the main and host config files for any other
# data they might need.

main_config_file=/usr/local/nagios/etc/nagios.cfg //line 15 here


# PHYSICAL HTML PATH
# This is the path where the HTML files for Nagios reside.  This
# value is used to locate the logo images needed by the statusmap
# and statuswrl CGIs.

physical_html_path=/usr/local/nagios/share

nagios.cfg 故意放在 conf.d/ 目录之外。列出的路径也是正确的:

[root@ip-172-31-46-232 conf.d]# locate nagios.cfg
/usr/local/nagios/etc/nagios.cfg

答案1

与 @mdpc 交谈后,我仔细检查了 Nagios 文档。文档并没有明确说明,但其中有以下内容:

默认情况下,Nagios 希望 CGI 配置文件名为 cgi.cfg,并与主配置文件一起位于配置文件目录中。

我将cgi.cfgnagios.cfg移回同一目录,一切顺利。我再次尝试进行飞行前检查,遇到完全相同的错误,但与我的resource.cfg文件有关。将配置文件移到与 cgi 和 nagios 文件相同的目录中,一切顺利。

所以现在我的目录内容/usr/local/nagios/etc/包括:

  • conf.d/ #包含 cfg 文件的分类子目录
  • 配置文件
  • nagios配置文件
  • 资源配置文件

真正令人沮丧的是,Nagios 文档中没有任何地方明确指出 cgi.cfg、nagios.cfg 和 resource.cfg 文件都需要位于同一目录中。

谢谢大家的建议。

答案2

我遇到了同样的问题 - 事实证明,问题不在于文件必须位于特定路径中,而是恰恰相反 - 我试图使用来自resource.cfg也使用定义扫描的路径的文件- 这导致 nagios 中的对象定义cfg_dir出现错误!$USERX$=xxx starts with an invalid token

另一方面,当我resource.cfg从另一条路径包含时,一切都运行良好!

希望这能帮助那些试图解决这个问题的人:-)

相关内容