Mass counter creation in XML

Apr 12, 2008 at 3:03 PM
Edited Apr 12, 2008 at 3:17 PM
Hi All,

Ive created an autohotkey script to mass create an extension to the PAL XML. It uses a tsv newcounters.tsv in this example. The format of the tsv is ANALYSIS NAME<TAB>ANALYZECOUNTER<TAB>CATEGORY<TAB>DESCRIPTION<TAB>CODE
ICA Session Latency - Last recorded \ICA Session(*)\Latency - Last recorded ICA Session Description of the Counter If blabla > 0 Then # do somethinig # End If

When the extension is ready, you can append it to the end of the XML being used.

In the fourth column you can also write a code, but replace newlines with # in order to fit it into one line.

I hope that it will be as useful as its for me.

Cheers,
Ferenc

; AutoHotkey Version: 1.0
; Language: English
; Author: Ferenc Matyas <ffmatyas@gmail.com>
;
; Script Function:
; creates additional parts to the PAL.XML file. replace all newlines with #.
; the format of the tsv is ANALYSIS NAME<TAB>ANALYZECOUNTER<TAB>CATEGORY<TAB>DESCRIPTION<TAB>CODE
; ICA Session Latency - Last recorded \ICA Session(*)\Latency - Last recorded ICA Session Description of the Counter If blabla > 0 Then # do somethinig # End If


#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

_xmlfile = %A_Hour%.%A_Min%.%A_Sec%.created.PAL.XML
;
_varname =

;FILE LOOP STARTS
Loop, read, newcounters.tsv
{
Loop, parse, A_LoopReadLine, %A_Tab%
{
Array%A_Index% = %A_LoopField%
}

StringReplace, _varname,Array2,\,, All
StringReplace, _varname,_varname,(*),_, All
StringReplace, _varname,_varname,%A_SPACE%,, All

StringReplace, Array5,Array5,#,`r`n, All

if Array5 =
{
; threshold and code is needed when there is no code present
FileAppend,
(
<ANALYSIS NAME="%Array1%" ENABLED="True" ANALYZECOUNTER="%Array2%" CATEGORY="%Array3%">`r`n
<COUNTER NAME="%Array2%" MINVARNAME="Min%_varname%" AVGVARNAME="Avg%_varname%" MAXVARNAME="Max%_varname%" TRENDVARNAME="Trend%_varname%" DATATYPE="integer" />`r`n
<CHART CHARTTITLE="%Array2%" OTSFORMAT="MM/dd hh:mm" GROUPSIZE="640x480" CATEGORIES="AUTO" DATATYPE="integer" LEGEND="ON" MAXCATEGORYLABELS="0" CHARTTYPE="Line" VALUES="AUTO" DATASOURCE="%Array2%" />`r`n
<DESCRIPTION><![CDATA[%Array4%]]></DESCRIPTION>`r`n
</ANALYSIS>`r`n
), %_xmlfile%
}
else
{
FileAppend,
(

<ANALYSIS NAME="%Array1%" ENABLED="True" ANALYZECOUNTER="%Array2%" CATEGORY="%Array3%">`r`n
<COUNTER NAME="%Array2%" MINVARNAME="Min%_varname%" AVGVARNAME="Avg%_varname%" MAXVARNAME="Max%_varname%" TRENDVARNAME="Trend%_varname%" DATATYPE="integer" />`r`n
<CHART CHARTTITLE="%Array2%" OTSFORMAT="MM/dd hh:mm" GROUPSIZE="640x480" CATEGORIES="AUTO" DATATYPE="integer" LEGEND="ON" MAXCATEGORYLABELS="0" CHARTTYPE="Line" VALUES="AUTO" DATASOURCE="%Array2%" />`r`n
<THRESHOLD NAME="%Array1%" CONDITION="Critical" COLOR="#FF0000" PRIORITY="100">`r`n
<DESCRIPTION><![CDATA[%Array4%]]></DESCRIPTION>`r`n
<CODE><![CDATA[%Array5%]]></CODE>`r`n
</THRESHOLD>`r`n
<DESCRIPTION><![CDATA[%Array4%]]></DESCRIPTION>`r`n
</ANALYSIS>`r`n
), %_xmlfile%
}
;FILE LOOP ENDS
}