Forum Discussion
9 years ago
On 5/1/2016 at 11:24 PM, Michael Horwath said:I might have an easier way..
Call this script directly then parse the output.
I included my datasource I created as well as XML for input into a datasource in your portal.
To have this for multiple 'groupIds' you may need to change things up (a little perl changes) by perhaps using a groovy script to pass in a variable (groupId?) for the different customers you wish to build this for. Shouldn't be hard.
#!/usr/bin/env perl ### this is the perl script you should call to output the count ### as needed # replace username with an administrative username # replace the password with .. the password of the user # example below works # don't forget to update the groupId as needed! Perhaps make it # a passed parameter via groovy script directly $userName="mike"; $password="pass.w0rd"; $sitename="sitename"; $siteurl="site.logicmonitor.com" $groupId="1"; $curlopt="'https://$siteurl/santaba/rpc/getAlerts?c=$sitename&u=$userName&p=$password&hostGroupId=$groupId'"; $curlrun="env curl -s $curlopt"; # Now we have the command to run $alertwarn=; $alerterr=; $alertcrit=; open(FILE, "-|", $curlrun) or die $!; while (<FILE>) { $alertwarn++ if /warn/; $alerterr++ if /error/; $alertcrit++ if /critical/; } close $handle; $alerttotal=$alertwarn+$alerterr+$alertcrit; print "warning:" . $alertwarn . "\n"; print "error:" . $alerterr . "\n"; print "critical:" . $alertcrit . "\n"; print "total:" . $alerttotal . "\n";<?xml version="1.0" encoding="UTF-8" ?> <feed version="1.0" hasPendingRequests="false" > <company></company> <status>200</status> <errmsg>OK</errmsg> <interval></interval> <entry type="predatasource"> <version>1391573679</version> <name>Count Alerts</name> <displayedas>_Count Alerts</displayedas> <description>Count number of alerts from LogicMonitor. Gathers warnings, errors, criticals, and a total number.</description> <collector>script</collector> <hasMultiInstances>false</hasMultiInstances> <schedule>600</schedule> <appliesTo>system.hostname == "insert-IP-here" or system.hostname == "insert-FQDN-here"</appliesTo> <wildcardauto>false</wildcardauto> <wildcardpersist>false</wildcardpersist> <wildcardlinuxscript></wildcardlinuxscript> <wildcardlinuxcmdline></wildcardlinuxcmdline> <wildcardwinscript></wildcardwinscript> <wildcardwincmdline></wildcardwincmdline> <wildcardgroovyscript></wildcardgroovyscript> <wildcardschedule>1440</wildcardschedule> <wildcarddisable>false</wildcarddisable> <agdmethod>none</agdmethod> <agdparams></agdparams> <group></group> <tags></tags> <technology></technology> <adlist><![CDATA[{"id":0,"agdmethod":"none","params":{},"agdparams":"","filters":[]}]]></adlist> <attributes> <attribute> <name>scripttype</name> <value>file</value> <comment></comment> </attribute> <attribute> <name>scriptgroovy</name> <value>import com.santaba.agent.groovyapi.expect.Expect; import com.santaba.agent.groovyapi.snmp.Snmp; import com.santaba.agent.groovyapi.http.*; import com.santaba.agent.groovyapi.jmx.*; import org.xbill.DNS.*;</value> <comment></comment> </attribute> <attribute> <name>windowsscript</name> <value></value> <comment></comment> </attribute> <attribute> <name>linuxscript</name> <value>/usr/local/logicmonitor/agent/lib/count-alerts.pl</value> <comment></comment> </attribute> <attribute> <name>windowscmdline</name> <value></value> <comment></comment> </attribute> <attribute> <name>linuxcmdline</name> <value></value> <comment></comment> </attribute> </attributes> <datapoints> <datapoint> <name>alertwarn</name> <dataType>7</dataType> <type>2</type> <postprocessormethod>namevalue</postprocessormethod> <postprocessorparam>warning</postprocessorparam> <usevalue>output</usevalue> <alertexpr>> 100</alertexpr> <alertmissing>1</alertmissing> <alertsubject></alertsubject> <alertbody></alertbody> <description></description> <maxvalue></maxvalue> <minvalue></minvalue> <userparam1></userparam1> <userparam2></userparam2> <userparam3></userparam3> <iscomposite>false</iscomposite> <rpn></rpn> <alertTransitionIval>2</alertTransitionIval> <alertClearTransitionIval></alertClearTransitionIval> </datapoint> <datapoint> <name>alerterror</name> <dataType>7</dataType> <type>2</type> <postprocessormethod>namevalue</postprocessormethod> <postprocessorparam>error</postprocessorparam> <usevalue>output</usevalue> <alertexpr>> 35 50</alertexpr> <alertmissing>1</alertmissing> <alertsubject></alertsubject> <alertbody></alertbody> <description></description> <maxvalue></maxvalue> <minvalue></minvalue> <userparam1></userparam1> <userparam2></userparam2> <userparam3></userparam3> <iscomposite>false</iscomposite> <rpn></rpn> <alertTransitionIval>2</alertTransitionIval> <alertClearTransitionIval></alertClearTransitionIval> </datapoint> <datapoint> <name>alertcritical</name> <dataType>7</dataType> <type>2</type> <postprocessormethod>namevalue</postprocessormethod> <postprocessorparam>critical</postprocessorparam> <usevalue>output</usevalue> <alertexpr>> 4 4 5</alertexpr> <alertmissing>1</alertmissing> <alertsubject></alertsubject> <alertbody></alertbody> <description></description> <maxvalue></maxvalue> <minvalue></minvalue> <userparam1></userparam1> <userparam2></userparam2> <userparam3></userparam3> <iscomposite>false</iscomposite> <rpn></rpn> <alertTransitionIval>2</alertTransitionIval> <alertClearTransitionIval></alertClearTransitionIval> </datapoint> <datapoint> <name>alerttotal</name> <dataType>7</dataType> <type>2</type> <postprocessormethod>namevalue</postprocessormethod> <postprocessorparam>total</postprocessorparam> <usevalue>output</usevalue> <alertexpr></alertexpr> <alertmissing>1</alertmissing> <alertsubject></alertsubject> <alertbody></alertbody> <description></description> <maxvalue></maxvalue> <minvalue></minvalue> <userparam1></userparam1> <userparam2></userparam2> <userparam3></userparam3> <iscomposite>false</iscomposite> <rpn></rpn> <alertTransitionIval>5</alertTransitionIval> <alertClearTransitionIval></alertClearTransitionIval> </datapoint> </datapoints> <graphs> <graph> <name>Alert Trending</name> <title>Alert Trending</title> <verticallabel>number</verticallabel> <rigid>true</rigid> <maxvalue>NaN</maxvalue> <minvalue>0.0</minvalue> <displayprio>1</displayprio> <timescale>1day</timescale> <base1024>false</base1024> <graphdatapoints> <graphdatapoint> <name>alertcritical</name> <datapointname>alertcritical</datapointname> <cf>2</cf> </graphdatapoint> <graphdatapoint> <name>alerterror</name> <datapointname>alerterror</datapointname> <cf>2</cf> </graphdatapoint> <graphdatapoint> <name>alerttotal</name> <datapointname>alerttotal</datapointname> <cf>2</cf> </graphdatapoint> <graphdatapoint> <name>alertwarn</name> <datapointname>alertwarn</datapointname> <cf>2</cf> </graphdatapoint> </graphdatapoints> <graphvirtualdatapoints> </graphvirtualdatapoints> <graphdatas> <graphdata> <type>2</type> <legend>Total</legend> <color>black</color> <datapointname>alerttotal</datapointname> <isvirtualdatapoint>false</isvirtualdatapoint> </graphdata> <graphdata> <type>1</type> <legend>Warnings</legend> <color>yellow</color> <datapointname>alertwarn</datapointname> <isvirtualdatapoint>false</isvirtualdatapoint> </graphdata> <graphdata> <type>1</type> <legend>Errors</legend> <color>orange</color> <datapointname>alerterror</datapointname> <isvirtualdatapoint>false</isvirtualdatapoint> </graphdata> <graphdata> <type>1</type> <legend>Criticals</legend> <color>red</color> <datapointname>alertcritical</datapointname> <isvirtualdatapoint>false</isvirtualdatapoint> </graphdata> </graphdatas> </graph> </graphs> <overviewgraphs> </overviewgraphs> </entry> </feed>
Hi Michael,
thanks for the reply. I was not able to import the XML file, but managed to recreate what you did :-).
Works like a charm, thanks!
Jeroen
Related Content
- 2 months ago
- 2 years ago
- 18 days ago