Change source name through pipeline example?

I’m trying to change the presented name of the Ubiquiti controller messages coming into Graylog through syslog. The controller is presenting itself as (“U7PG2,802aa8d014b6,v3.9.3.7537”) and I’m trying to get it to show up as simply unifi.[] which is how we access it.

I’m very new to Graylog and tried a pipeline rule like this.

rule “UbiquitiSwapSource”
$message.source == “(“u7pg2,802aa8d014b6,v3.9.3.7537”)”
set_field("$message.source", “”);

The pipeline is connected to ‘all messages’ and other pipelines appear to work. Is this a bad way to attempt this? Are there better ways?

rule "UbiquitiSwapSource"
  to_string($message.source) == "u7pg2,802aa8d014b6,v3.9.3.7537"
  set_field("source", "");

If you have lots of devices and want to replace the “source” message field for each of them, take a look at lookup tables:

I managed to get a lookup table so when I query (“u7pg2,802aa8d014b6,v3.9.3.7537”) the lookup comes back with:

“single_value”: “UniFi Cloud Controller”,
“multi_value”: {
“value”: “UniFi Cloud Controller”
“ttl”: 9223372036854776000

I added a table extractor to the input stream and from inside the extractor it appears to show a match but never gets triggered.

The store as field should be “source” to overwrite it yes?

well after an hour or so the name on two devices began to get swapped with the lookup table but the one source that arrives as (“u7pg2,802aa8d014b6,v3.9.3.7537”) stayed as (“u7pg2,802aa8d014b6,v3.9.3.7537”).

This sounds like a problem with the timestamps in your messages.

If the timestamp in the log messages doesn’t include any timezone information, Graylog will treat it as if it was UTC.

I have some unifi devices myself and use the following rules to get a “valid” hostname:

rule "unifi split source"
  has_field("source") AND
  contains(to_string($message.source), "U7LT") OR 
  contains(to_string($message.source), "US8P60") OR 
  contains(to_string($message.source), "US16P150")
  // didn't yet find a better way doing this

 // clean up source and get device information out of the fucking string that is provided as source
 // needs the following defined grok pattern in the system
 // UNIFIYSOURCES = ("%{WORD:device_type},%{WORD:device_mac},%{NOTSPACE:device_version}")
 let source_field = to_string($message.source);
 let source_split = grok(pattern: "%{UNIFIYSOURCES}", value: source_field, only_named_captures: true); 

That helps me to have all three available information in a single field (and I can spot easy when a software update is not yet rolled out complete).

After that you have two options, depending of the number of devices you have. Create a second stage in the pipeline and write one rule for each device like

rule "unifi set hostname (802aa893d851)"
    has_field("device_mac") AND contains(to_string($message.device_mac), "802aa893d851")
    set_field("source", "ap-office.lan");

Or create a lookup table that contains the device MACs and hostnames and use that in one rule to fit all devices.

rule "unifi set hostname from LUT"
	// use as much fields as possible to 
	// remove false lookups if device_mac might be present
	// on other messages
    has_field("device_mac") AND
    // get hostname based on MAC for unifi devices
    let update_source = lookup_value("unifi-hostname-lookuptable", $message.device_mac);
    set_field("source", update_source);

I’ll test that approach. The lookup table did start working about 9 hours after I set it up. The hostnames began to appear instead of the (“name”) that was showing up.

The firewall was sending out a timestamp set to the wrong timezone, working well now.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.