Configuration

Nagios 配置錯誤:飛行前檢查期間出現“意外的令牌或文件中的語句”

  • April 7, 2016

我在 CentOS 6.5 上使用 Nagios 3.2.3。期間一切install順利make。我轉移了我的 conf 文件,進行了適當的更改,並對我的 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

在與@mdpc 交談後,我仔細檢查了 Nagios 文件。它根本沒有說清楚,也沒有放在你的臉上,但它是這樣說的:

預設情況下,Nagios 期望 CGI 配置文件命名為 cgi.cfg 並與主配置文件一起位於配置文件目錄中。

我將cgi.cfgandnagios.cfg移回了同一個目錄,它執行良好。我再次嘗試飛行前檢查,但遇到了完全相同的錯誤,但與我的resource.cfg文件有關。將配置文件移動到與 cgi 和 nagios 文件相同的目錄中,並且執行良好。

所以現在我的目錄內容/usr/local/nagios/etc/包括:

  • conf.d/ #包含 cfg 文件的分類子目錄
  • cgi.cfg
  • nagios.cfg
  • 資源.cfg

真正令人沮喪的是,Nagios 文件中沒有任何地方明確聲明 cgi.cfg、nagios.cfg 和 resource.cfg 文件都需要位於同一目錄中。

謝謝你們的建議,伙計們。

引用自:https://serverfault.com/questions/636662