I would like to add some fields to the data sent by Metricbeat. My machines have a hostname like this AA-BBB-CCXX where A, B, C are letters and X numbers. I would like to have :
host.group: "AA-BBB-CC"
host.number: "XX"
Metricbeat already sends host.name containing the full hostname.
I have tried this in system.yml using the script processor :
- module: system
period: 10s
metricsets:
- process
processors:
- add_tags:
tags: [session_stats]
- script:
lang: javascript
id: host_metadata
source: >
function process(event) {
var hostn = event.Get("hostname"); // does not work
var regex_num_end = /[0-9]+$/g;
var host_number = hostn.match(regex_num_end)[0];
var host_group = hostn.replace(regex_num_end, "");
event.Put("host.number",host_number);
event.Put("host.group",host_group);
}
event.Get("host.name")
does not work either and return null. The code works if I hardcode the hostname though.
I also tried to use the dissect processor without success.
Thanks