|
Copyright (c) 2008 Nico Bagari & Thomas Buffagni Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License". One of default plug-in used for parsing Nagios Line is the java class org.brainypdm.plugins.nagios.RegExpr. This class help you to create some parser based on regular expression. Let me show this example. - you have to parse a line like this: 1217662225||localhost||OK||0.015||myservice||myservice description||A=3 B=2 You can see that this line don't have the UOM (unit of measurement), but it's not a problem. - create and test your regular expression The first step is create the regular expression. For this example a simple regular expression is: (A|B)=(\d+) How can test it ? You can test with BrainyPDM console; go in $BRAINY_HOME and type ./console.sh. brainypdm>regexpr "(A|B)=(\d+)" "A=3 B=2" group(0)=A=3 group(1)=A group(2)=3 group(0)=B=2 group(1)=B group(2)=2 This output tell that this regular expression is correct for you; infact in the group(1) there is the performanca data name and in group(2) there is the performance data value for all performance data. - setting new definition with your regular expression Open the file $BRAINY_HOME/plugins/nagios/nagios-def.xml and add this section: <plugins> <plugin> <name>example</name> <className>org.brainypdm.plugins.nagios.RegExpr</className> <description> <![CDATA[example]]> </description> <unique>false</unique> <serviceFilter> <![CDATA[myservice]]> </serviceFilter> <hostFilter> <![CDATA[localhost]]> </hostFilter> <overwriteOrder>10</overwriteOrder> <perfDataIgnoreFilter/> <idle>false</idle> <test>true</test> <parseOutput>false</parseOutput> <parsePerfData>true</parsePerfData> <matchOutput/> <params> <param> <name>regExpr</name> <value> <![CDATA[(A|B)=(\d+)]]> </value> </param> <param> <name>labelGroup</name> <value>1</value> </param> <param> <name>valueGroup</name> <value>2</value> </param> <param> <name>forcedUom</name> <value>4</value> </param> </params> </plugin> </plugins> Note on xml tags: - serviceFilter: in this tag you tell to BrainyPDM that this definition parse only service with service name that match with this regular expression. - hostFilter: the host name must match this regular expression - overwriteOrder: lesser value for this tag tell BrainyPDM that this plug-in definition have major weight (the maximum weight is 0) - test: if true BrainyPDM don't save performance data found with this definition. - parsePerfdata: if true parse this macro $SERVICEPERFDATA$ - forcedUom: BrainyPDM want always a UOM (unit of measurement) for a performance data so we tell that UOM have id=4, the "counter" UOM. - reloading the plug-in definition you have to notify to BrainyPDM that the file is changed; open BrainyPDM console: brainypdm>nagios -r plugin definition reloaded - test your definition You can test your definition with nagios line. Create file $BRAINY_HOME/plugins/nagios/nagios-test-input.txt and put the nagios line that you want test it in the file: 1217662225||localhost||OK||0.015||myservice||myservice description||A=3 B=2 Now open BrainyPDM console: brainypdm>nagios -L Processing file /opt/brainyFull/plugins/nagios/nagios-test-input.txt ... Sending line ... 1217662225||localhost||OK||0.015||myservice||myservice description||A=3 B=2 Host: localhost Service: myservice Service status: 0 | 0.015 | 2008-08-02 09:30:25.0 Performance Data (label=value[UOM];[warn];[crit];[min];[max]): A=3.0 [count];0.0;0.0;0.0;0.0 Performance Data (label=value[UOM];[warn];[crit];[min];[max]): B=2.0 [count];0.0;0.0;0.0;0.0 It works !!! - enable plug-in The last step is set in your definition file <test>false</test> and reload the definition in BrainyPDM console with the command "nagios -r". You have finished !!! For any suggestion, please, contact us. Thank you.
Last update: 04-08-2008
|