做为Nagios插件的脚本或执行程序必须(至少)要作两件事: 退出时给出几种可能的返回值中的一个; 至少要给出一条输出内容到标准输出设备(STDOUT)。 Nagios用插件的返回值来生成主机或服务的状态。下表里列出了合法的返回值以及对应的服务或主机状态。 插件返回值 服务状态 主机状态 0 正常(OK) 运行(UP) 1 警告(WARNING) 运行(UP)或宕机(DOWN)/不可达(UNREACHABLE)* 2 紧急(CRITICAL) 宕机(DOWN)/不可达(UNREACHABLE) 3 未知(UNKNOWN) 宕机(DOWN)/不可达(UNREACHABLE) 特定插件输出: 最小状况下,插件要返回一行文本输出。自Nagios 3版本起,插件能够返回多行输出文本。 插件能够返回性能数据以让外部应用来作后序处理。 文本输出和性能数据中间要以"|"来分隔 例如 DISK OK - free space: / 4466MB (70%); | /=2648MB;6022;6022;0;6022" "|"以前保存在$SERVICEOUTPUT$宏里 "|"以后的是性能数据,保存在$SERVICEPERFDATA$宏里 The Nagios daemon doesn't directly process performance data, so it doesn't really care what the performance data looks like. There aren't really any inherent limitations on the format or content of the performance data. However, if you are using an external addon to process the performance data (i.e. PerfParse), the addon may be expecting that the plugin returns performance data in a specific format. C check the documentation that comes with the addon for more information. 简单的说就是:对于性能数据nagios并不关心它是什么,格式具体是什么;性能数据的格式由须要处理这些数据的插件来决定。 nagios3之后,插件能够返回多行文本: TEXT OUTPUT | OPTIONAL PERFDATA LONG TEXT LINE 1 LONG TEXT LINE 2 ... LONG TEXT LINE 部分保存在$LONGSERVICEOUTPUT$宏里。