Summary

Event forwarding routes ingested events to an external destination through a configured event forwarder. A forwarding rule is scoped to a single repository. It controls which events reach a given forwarder. The rule's query string uses LogScale query language to filter events; only events that match the filter are forwarded. Field assignments in the query string can rename or remove fields. They take effect before events are sent to the forwarder.

The createEventForwardingRule() mutation creates a new forwarding rule and returns the created rule. The return type is non-null: the mutation returns an error rather than null on failure. To modify an existing rule, call updateEventForwardingRule(). To remove a rule, call deleteEventForwardingRule().

Syntax

graphql
createEventForwardingRule(
      input: CreateEventForwardingRule!
   ): EventForwardingRule!

The input argument is required and takes a CreateEventForwardingRule object. Provide the repository name, the event forwarder ID, and the query string. See the Input Parameters section for field details.

The mutation returns an EventForwardingRule! object. The non-null return type means the mutation returns an error on failure rather than null. Request id in your return fields to obtain the rule identifier. Supply this identifier to subsequent updateEventForwardingRule() and deleteEventForwardingRule() calls.

Example

Raw
graphql
mutation {
  createEventForwardingRule(input:
      { repoName: "humio",
        queryString: "@host=localhost",
        eventForwarderId: "RhLcbl3OJcjfIOmfPyLxVUpR9I2Fma6K",
        languageVersion: legacy
      } )
  { id }
}
Mac OS or Linux (curl)
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "mutation {
  createEventForwardingRule(input:
      { repoName: \"humio\",
        queryString: \"@host=localhost\",
        eventForwarderId: \"RhLcbl3OJcjfIOmfPyLxVUpR9I2Fma6K\",
        languageVersion: legacy
      } )
  { id }
}"
}
EOF
Mac OS or Linux (curl) One-line
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql \
    -H "Authorization: Bearer $TOKEN" \
    -H "Content-Type: application/json" \
    -d @- << EOF
{"query" : "mutation {
  createEventForwardingRule(input:
      { repoName: \"humio\",
        queryString: \"@host=localhost\",
        eventForwarderId: \"RhLcbl3OJcjfIOmfPyLxVUpR9I2Fma6K\",
        languageVersion: legacy
      } )
  { id }
}"
}
EOF
Windows Cmd and curl
shell
curl -v -X POST $YOUR_LOGSCALE_URL/graphql ^
    -H "Authorization: Bearer $TOKEN" ^
    -H "Content-Type: application/json" ^
    -d @'{"query" : "mutation { ^
  createEventForwardingRule(input: ^
      { repoName: \"humio\", ^
        queryString: \"@host=localhost\", ^
        eventForwarderId: \"RhLcbl3OJcjfIOmfPyLxVUpR9I2Fma6K\", ^
        languageVersion: legacy ^
      } ) ^
  { id } ^
}" ^
} '
Windows Powershell and curl
powershell
curl.exe -X POST 
    -H "Authorization: Bearer $TOKEN"
    -H "Content-Type: application/json"
    -d '{"query" : "mutation {
  createEventForwardingRule(input:
      { repoName: \"humio\",
        queryString: \"@host=localhost\",
        eventForwarderId: \"RhLcbl3OJcjfIOmfPyLxVUpR9I2Fma6K\",
        languageVersion: legacy
      } )
  { id }
}"
}'
    "$YOUR_LOGSCALE_URL/graphql"
Perl
perl
#!/usr/bin/perl

use HTTP::Request;
use LWP;

my $TOKEN = "TOKEN";

my $uri = '$YOUR_LOGSCALE_URL/graphql';

my $query = "mutation {
  createEventForwardingRule(input:
      { repoName: \"humio\",
        queryString: \"@host=localhost\",
        eventForwarderId: \"RhLcbl3OJcjfIOmfPyLxVUpR9I2Fma6K\",
        languageVersion: legacy
      } )
  { id }
}";
$query =~ s/\n/ /g;
my $json = sprintf('{"query" : "%s"}',$query);
my $req = HTTP::Request->new("POST", $uri );

$req->header("Authorization" => "Bearer $TOKEN");
$req->header("Content-Type" => "application/json");

$req->content( $json );

my $lwp = LWP::UserAgent->new;

my $result = $lwp->request( $req );

print $result->{"_content"},"\n";
Python
python
#! /usr/local/bin/python3

import requests

url = '$YOUR_LOGSCALE_URL/graphql'
mydata = r'''{"query" : "mutation {
  createEventForwardingRule(input:
      { repoName: \"humio\",
        queryString: \"@host=localhost\",
        eventForwarderId: \"RhLcbl3OJcjfIOmfPyLxVUpR9I2Fma6K\",
        languageVersion: legacy
      } )
  { id }
}"
}'''

resp = requests.post(url,
                     data = mydata,
                     headers = {
   "Authorization" : "Bearer $TOKEN",
   "Content-Type" : "application/json"
}
)

print(resp.text)
Node.js
javascript
const https = require('https');

const data = JSON.stringify(
    {"query" : "mutation {
  createEventForwardingRule(input:
      { repoName: \"humio\",
        queryString: \"@host=localhost\",
        eventForwarderId: \"RhLcbl3OJcjfIOmfPyLxVUpR9I2Fma6K\",
        languageVersion: legacy
      } )
  { id }
}"
}
);


const options = {
  hostname: '$YOUR_LOGSCALE_URL',
  path: 'graphql',
  port: 443,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Content-Length': data.length,
    Authorization: 'BEARER ' + process.env.TOKEN,
    'User-Agent': 'Node',
  },
};

const req = https.request(options, (res) => {
  let data = '';
  console.log(`statusCode: ${res.statusCode}`);

  res.on('data', (d) => {
    data += d;
  });
  res.on('end', () => {
    console.log(JSON.parse(data).data);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.write(data);
req.end();
Example Responses
Success (HTTP Response Code 200 OK)
json
{
  "data": {
    "createEventForwardingRule": {
      "id": "abc123"
    }
  }
}

Input Parameters

The input argument accepts a CreateEventForwardingRule object. The rule is scoped to the repository named in repoName. It does not apply to views or other repositories. Provide the eventForwarderId of an existing configured forwarder. This identifies the external destination for forwarded events.

The queryString field accepts a LogScale query string. Events that match the filter are forwarded. Include field assignments in the query string to rename or remove fields before forwarding. The languageVersion field controls how the query string is parsed.

Table: CreateEventForwardingRule Input Datatype

ParameterTypeRequiredDefaultStabilityAvailabilityDescription
eventForwarderIdStringyes   The id of the event forwarder
languageVersionLanguageVersionEnum     
queryStringStringyes   The query string for filtering and mapping the events to forward
repoNameStringyes   The name of the repository that the event forwarding rule is for

Returned Values

The mutation returns the newly created EventForwardingRule object. Request id to obtain the rule identifier. Supply it to subsequent updateEventForwardingRule() and deleteEventForwardingRule() calls. Request eventForwarderId, queryString, and languageVersion to confirm the saved configuration.