Message Script
var message = new RestRequestMessage();
var body = '';
var firstLine = true;
var ts_type = 'misc'; // Declare a variable for the ts_type tag
// Process the ready-to-publish time series
for (var i = 0; i < dataContext.series.length; i++)
{
var ts = dataContext.series[i];
// Determine the value of the ts_type tag
// based on the path of the time series
if (ts.path.includes('Power'))
ts_type = 'power';
else if (ts.path.includes('Alarms'))
ts_type = 'alarm';
else if (ts.path.includes('Fuel'))
ts_type = 'fuel';
// Process the samples of the i-th time series
for (var j = 0; j < ts.samples.length; j++)
{
var sample = ts.samples[j];
if (!firstLine)
body += '\n'; // If at least one line was added, insert a line break
// Generate a string like this:
// rest_measures,ts_path=Plant.Generator1.Power full.kWh value=280.87124,status=0,ts_type='power' 1591172295193
body += 'rest_measures,ts_path=' + ts.path
+ ' value=' + sample.value.toFixed(5)
+ ',status=' + sample.status
+ ', ts_type=' + ts_type
+ ' ' + sample.time.getTime();
firstLine = false;
}
}
// Specifying the final string as the HTTP request body
message.body = body;
return message;Last updated