<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<formatVersion>3</formatVersion>
	<description></description>
	<events>
	</events>
	<templates>
		<template id="34735">
			<name>Availability</name>
			<flags>0</flags>
			<dataCollection>
				<dci id="2855">
					<name>Dummy</name>
					<description>MTBF (hours)</description>
					<dataType>4</dataType>
					<origin>0</origin>
					<interval>60</interval>
					<retention>30</retention>
					<instance></instance>
					<systemTag></systemTag>
					<delta>0</delta>
					<advancedSchedule>0</advancedSchedule>
					<allThresholds>0</allThresholds>
					<rawValueInOctetString>0</rawValueInOctetString>
					<snmpRawValueType>0</snmpRawValueType>
					<snmpPort>0</snmpPort>
					<transformation>return GetCustomAttribute($node, &quot;mtbf&quot;);</transformation>
					<thresholds>
					</thresholds>
				</dci>
				<dci id="2856">
					<name>Dummy</name>
					<description>Failures</description>
					<dataType>0</dataType>
					<origin>0</origin>
					<interval>60</interval>
					<retention>30</retention>
					<instance></instance>
					<systemTag></systemTag>
					<delta>0</delta>
					<advancedSchedule>0</advancedSchedule>
					<allThresholds>0</allThresholds>
					<rawValueInOctetString>0</rawValueInOctetString>
					<snmpRawValueType>0</snmpRawValueType>
					<snmpPort>0</snmpPort>
					<transformation>return GetCustomAttribute($node, &quot;NumFailures&quot;);</transformation>
					<thresholds>
					</thresholds>
				</dci>
				<dci id="2857">
					<name>Dummy</name>
					<description>Node availability (percentage)</description>
					<dataType>4</dataType>
					<origin>0</origin>
					<interval>60</interval>
					<retention>30</retention>
					<instance></instance>
					<systemTag></systemTag>
					<delta>0</delta>
					<advancedSchedule>0</advancedSchedule>
					<allThresholds>0</allThresholds>
					<rawValueInOctetString>0</rawValueInOctetString>
					<snmpRawValueType>0</snmpRawValueType>
					<snmpPort>0</snmpPort>
					<transformation>// This script calculates MTTR, MTBF and perAvailability parameters and stores them in custom attributes &#x0D;&#x0A;// Initialize some custom attributes the first time. &#x0D;&#x0A;// Undefined attributes are created by SetCustomAttribute function automatically&#x0D;&#x0A;CurrentStatus = GetDCIValue($node, FindDCIByName($node, &quot;Status&quot;));&#x0D;&#x0A;PreviousState = GetCustomAttribute($node, &quot;PreviousState&quot;);&#x0D;&#x0A;if (PreviousState == null)&#x0D;&#x0A;{ // In the first time, previous state is null&#x0D;&#x0A;&#x09;SetCustomAttribute($node, &quot;PreviousState&quot;, CurrentStatus);&#x0D;&#x0A;&#x09;SetCustomAttribute($node, &quot;TimeStamp&quot;, time());&#x09; &#x0D;&#x0A;&#x09;SetCustomAttribute($node, &quot;NumFailures&quot;, 0);  &#x0D;&#x0A;&#x09;SetCustomAttribute($node, &quot;TotalUptime&quot;, 0);&#x0D;&#x0A;&#x09;SetCustomAttribute($node, &quot;TotalDowntime&quot;, 0);&#x0D;&#x0A;&#x09;return 100;&#x0D;&#x0A;}&#x0D;&#x0A;&#x0D;&#x0A;// From here the 2nd and subsequent times&#x0D;&#x0A;NumFailures = GetCustomAttribute($node, &quot;NumFailures&quot;);&#x0D;&#x0A;LastTime = time() - GetCustomAttribute($node, &quot;TimeStamp&quot;);&#x0D;&#x0A;&#x0D;&#x0A;// Status is up &#x0D;&#x0A;if (CurrentStatus == 0)&#x0D;&#x0A;{&#x0D;&#x0A;&#x09;if (PreviousState != CurrentStatus)&#x0D;&#x0A;&#x09;{&#x09;// just changed to up&#x0D;&#x0A;&#x09;&#x09;// update mttr&#x0D;&#x0A;&#x09;&#x09;TotalDowntime = GetCustomAttribute($node, &quot;TotalDowntime&quot;) + LastTime;&#x0D;&#x0A;&#x09;&#x09;mttr = TotalDowntime / ((NumFailures == 0) ? 1 : NumFailures) / 3600;&#x09;// to prevent division by ze&#x0D;&#x0A;&#x09;&#x09;SetCustomAttribute($node, &quot;TotalDowntime&quot;, TotalDowntime);&#x0D;&#x0A;&#x09;&#x09;SetCustomAttribute($node, &quot;mttr&quot;, mttr);&#x0D;&#x0A;&#x09;}&#x0D;&#x0A;&#x09;else&#x0D;&#x0A;&#x09;{&#x09;&#x09;// still up&#x0D;&#x0A;&#x09;&#x09;// update mtbf&#x0D;&#x0A;&#x09;&#x09;TotalUptime = GetCustomAttribute($node, &quot;TotalUptime&quot;) + LastTime;&#x0D;&#x0A;&#x09;&#x09;mtbf = TotalUptime / ((NumFailures == 0) ? 1 : NumFailures) / 3600;&#x09;// to prevent division by zero&#x0D;&#x0A;&#x09;&#x09;SetCustomAttribute($node, &quot;TotalUptime&quot;, TotalUptime);&#x0D;&#x0A;&#x09;&#x09;SetCustomAttribute($node, &quot;mtbf&quot;, mtbf);&#x0D;&#x0A;&#x09;}&#x0D;&#x0A;}&#x0D;&#x0A;&#x0D;&#x0A;// Status is down&#x0D;&#x0A;if (CurrentStatus == 4)&#x0D;&#x0A;{&#x0D;&#x0A;&#x09;if (PreviousState != CurrentStatus)&#x0D;&#x0A;&#x09;{&#x09;// just changed to down&#x0D;&#x0A;&#x09;&#x09;// update mtbf&#x0D;&#x0A;&#x09;&#x09;NumFailures++;&#x0D;&#x0A;&#x09;&#x09;TotalUptime = GetCustomAttribute($node, &quot;TotalUptime&quot;) + LastTime;&#x0D;&#x0A;&#x09;&#x09;mtbf = TotalUptime / NumFailures / 3600;&#x0D;&#x0A;&#x09;&#x09;SetCustomAttribute($node, &quot;NumFailures&quot;, NumFailures);&#x0D;&#x0A;&#x09;&#x09;SetCustomAttribute($node, &quot;TotalUptime&quot;, TotalUptime);&#x0D;&#x0A;&#x09;&#x09;SetCustomAttribute($node, &quot;mtbf&quot;, mtbf);&#x0D;&#x0A;&#x09;}&#x0D;&#x0A;&#x09;else&#x0D;&#x0A;&#x09;{&#x09;// still down&#x0D;&#x0A;&#x09;&#x09;// update mttr&#x0D;&#x0A;&#x09;&#x09;TotalDowntime = GetCustomAttribute($node, &quot;TotalDowntime&quot;) + LastTime;&#x0D;&#x0A;&#x09;&#x09;mttr = TotalDowntime / NumFailures / 3600;&#x0D;&#x0A;&#x09;&#x09;SetCustomAttribute($node, &quot;TotalDowntime&quot;, TotalDowntime);&#x0D;&#x0A;&#x09;&#x09;SetCustomAttribute($node, &quot;mttr&quot;, mttr);&#x0D;&#x0A;&#x09;&#x09;&#x0D;&#x0A;&#x09;}&#x0D;&#x0A;}&#x0D;&#x0A;&#x0D;&#x0A;If (CurrentStatus == 0 || CurrentStatus == 4)&#x0D;&#x0A;{&#x0D;&#x0A;&#x09;// Save previous state and timestamp&#x0D;&#x0A;&#x09;SetCustomAttribute($node, &quot;PreviousState&quot;, CurrentStatus);&#x0D;&#x0A;&#x09;SetCustomAttribute($node, &quot;TimeStamp&quot;, time());&#x09; &#x0D;&#x0A;&#x0D;&#x0A;&#x09;// perAvailability section&#x0D;&#x0A;&#x09;TotalUptime = GetCustomAttribute($node, &quot;TotalUptime&quot;);&#x0D;&#x0A;&#x09;TotalDowntime = GetCustomAttribute($node, &quot;TotalDowntime&quot;);&#x0D;&#x0A;&#x09;perAvailability = TotalUptime / (TotalUptime + TotalDowntime) * 100;&#x0D;&#x0A;&#x09;SetCustomAttribute($node, &quot;perAvailability&quot;, perAvailability);&#x0D;&#x0A;&#x0D;&#x0A;&#x09;return perAvailability;&#x0D;&#x0A;}&#x0D;&#x0A;</transformation>
					<thresholds>
					</thresholds>
				</dci>
				<dci id="2858">
					<name>Dummy</name>
					<description>MTTR (hours)</description>
					<dataType>4</dataType>
					<origin>0</origin>
					<interval>60</interval>
					<retention>30</retention>
					<instance></instance>
					<systemTag></systemTag>
					<delta>0</delta>
					<advancedSchedule>0</advancedSchedule>
					<allThresholds>0</allThresholds>
					<rawValueInOctetString>0</rawValueInOctetString>
					<snmpRawValueType>0</snmpRawValueType>
					<snmpPort>0</snmpPort>
					<transformation>return GetCustomAttribute($node, &quot;mttr&quot;);</transformation>
					<thresholds>
					</thresholds>
				</dci>
			</dataCollection>
		</template>
	</templates>
	<traps>
	</traps>
</configuration>
