Split log message on space for grok pattern - regex

I am two days new to grok and ELK.
I am struggling with breaking up the log messages based on space and make them appear as different fields in the logstash.
My input pattern is:
2022-02-11 11:57:49 - app - INFO - function_name=add elapsed_time=0.0296 input_params=6_3
I would like to see different fields in the logstash/kibana for function_name, elapsed_time and input_params.
At the moment, I have a following .conf
input{
file{
path => "/path/to/log/file"
start_position => "beginning"
}
}
filter{
grok{
match => {"message" => "%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:log-level} %{(?<function_name>[^.]*)\.(?<elapsed_time>[^.]*)\.(?<input>[^.]*)}"}
}
date {
match => ["timestamp", "ISO8601"]
}
function_name {
match => ["function_name", "DATA"]
}
elapsed_time {
match => ["elapsed_time", "BASE16FLOAT"]
}
input {
match => ["input", "DATA"]
}
}
output{
elasticsearch{
hosts => ["localhost:9200"]
index => "math_apis"
}
stdout{codec => rubydebug}
}
But this only produces a following message in logstash
{
"host" => "hostname",
"#timestamp" => 2022-02-11T06:27:49.404Z,
"message" => "2022-02-11 11:57:49 - app - INFO - function_name=add elapsed_time=0.0296 input_params=6_3",
"path" => "path/to/log/file",
"#version" => "1",
"tags" => [
[0] "_grokparsefailure"
]
}

You can use the following pattern:
%{TIMESTAMP_ISO8601:timestamp} - \S+ - %{LOGLEVEL:log_level} - function_name=%{NOTSPACE:function_name} elapsed_time=%{NOTSPACE:elapsed_time} input_params=%{NOTSPACE:input}
Details:
%{TIMESTAMP_ISO8601:timestamp} - timestamp field
- - a literal string
\S+ - any one or more non-whitespace chars
- - a literal string
%{LOGLEVEL:log_level} - LOGLEVEL pattern
- function_name= - a literal string
%{NOTSPACE:function_name} - function_name field of one or more non-whitespace chars
elapsed_time= - space and elapsed_time= string
%{NOTSPACE:elapsed_time} - elapsed_time field of one or more non-whitespace chars
input_params= - literal string
%{NOTSPACE:input} - input field of one or more non-whitespace chars.
See more about Grok patterns here.
Test output:
{
"timestamp": [
[
"2022-02-11 11:57:49"
]
],
"YEAR": [
[
"2022"
]
],
"MONTHNUM": [
[
"02"
]
],
"MONTHDAY": [
[
"11"
]
],
"HOUR": [
[
"11",
null
]
],
"MINUTE": [
[
"57",
null
]
],
"SECOND": [
[
"49"
]
],
"ISO8601_TIMEZONE": [
[
null
]
],
"log_level": [
[
"INFO"
]
],
"function_name": [
[
"add"
]
],
"elapsed_time": [
[
"0.0296"
]
],
"input": [
[
"6_3"
]
]
}

Related

How to pay a specific invoice in netsuite? using customerPayment

I am trying to pay a specific invoice using the customerpaymet endpoint, I made the JSON structure using the documentation from https://system.netsuite.com/help/helpcenter/en_US/APIs/REST_API_Browser/record/v1/2021.1/index.html#/definitions/customerPayment-applyCollection
This is my JSON:
{
"aracct": {
"id": "259"
},
"autoApply": false,
"apply": {
"items": [
{
"amount": 12.06,
"apply": true,
"doc": {
"id": 5517
}
}
]
},
"tranDate": "2021-10-13 3:34:01 PM",
"customForm": {
"id": "70"
},
"customer": {
"id": "3645"
},
"payment": 12.06,
"subsidiary": {
"id": "3"
}
}
This is the error:
{
"detail": "Error while accessing a resource. You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist.",
"o:errorPath": "apply",
"o:errorCode": "USER_ERROR"
}
I would appreciate any help!
This is how i do it in PHP, you can look at it for ideas on what you can try changing.
$request = [
'record_data' => [
[
'internalid' => $nsOrder['internalId'],
'source_type' => 'invoice',
'result_type' => 'customerpayment',
'transform_values' => '',
'literal_fields'=> [
'undepfunds' => 'F',
'account' => '123',
'customer' => $nsOrder['entity']['internalId'],
'paymentmethod' => '8',//cc
'memo' => $message,
],
'sublists'=> [
['name'=>'apply',
'update' => [
[
'match'=> 'internalid',
'data'=>[
'internalid'=>$nsOrder['internalId'],
'apply'=>'T',
'amount' => $nsOrder['amountRemaining']
]
]
]
]
]
]
]
];
$result = $this->curl->transform($request);
The answer is that you need to select a combination of Undep Funds | PaymentMethod and Account in order for this to succeed. The documentation for this exists here

Facebook Marketing API Placement asset customization asset_feed_spec error

I'v been trying to automatically generate ads with different content based on the placements (facebook-feed, messenger-story). I'v been trying to follow the documentation.
https://developers.facebook.com/docs/marketing-api/dynamic-creative/placement-asset-customization#asset-feed
But for some reason, it returns an error saying that the entire object_story_spec is wrong. But this probably has to do something with my asset_feed_spec, because it's the only thing I have been changing.
object_story_spec param is invalid
Object story spec is ill formed. Maybe missing Page ID or creative details, or invalid fields exist
Have anyone tried to do this before? Or is there any way for me to get a clearer error message?
Here is the code I'm using when trying to create the creative.
$creative->setData([
AdCreativeFields::CALL_TO_ACTION_TYPE => $callToAction,
AdCreativeFields::IMAGE_HASH => $image_hash,
AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
AdCreativeFields::ASSET_FEED_SPEC => $this->getAssetFeedSpec($post_message, $link_url, $headline, $image_hash, $description)
]);
To make it a bit more readable, I created a function that creates the different Asset feed specifications. To understand it a bit better, see the example in the documentation.
https://developers.facebook.com/docs/marketing-api/dynamic-creative/placement-asset-customization#supported-fields
public function getAssetFeedSpec($post_message, $link_url, $headline, $image_hash, $description) {
return [
'images' => [
[
'hash' => $image_hash
]
],
'bodies' => [
[
'adlabels' => [
[
'name' => 'labelfirst',
]
],
'text' => $post_message
],
[
'adlabels' => [
[
'name' => 'labelsecond',
]
],
'text' => $headline
]
],
'titles' => [
[
'text' => $headline
]
],
'descriptions' => [
[
'text' => $description
]
],
'ad_formats' => [
'SINGLE_IMAGE'
],
'call_to_action_types' => [
'LEARN_MORE'
],
'link_urls' => [
[
'website_url' => $link_url
]
],
'videos' => [],
'asset_customization_rules' => $this->getAssetCustomizationRules()
];
}
I also separated the asset_customization_rules to make that a bit more understandable.
public function getAssetCustomizationRules() {
return [
[
'customization_spec' => [
'publisher_platforms' => [
'facebook',
'instagram',
'audience_network',
'messenger'
],
'facebook_positions' => [
'feed',
],
'instagram_positions' => [
'stream'
],
'audience_network_positions' => [
'classic'
]
],
'body_label' => [
'name' => 'labelfirst'
]
],
[
'customization_spec' => [
'publisher_platforms' => [
'messenger'
],
'messenger_positions' => [
'stream'
]
],
'body_label' => [
'name' => 'labelsecond'
]
]
];
}
To generate creative, you need to pass object_story_spec with valid page_id just like below,
{
"object_story_spec": {
"page_id": "10506210208xxx"
},
"asset_feed_spec": {
"videos": [
{
"adlabels": [
{
"name": "placement_asset_3667064314xxx"
}
],
"video_id": "3667064314xxx"
},
..
It should work after providing a valid page_id, It's working for me.

How to capture a filename with or without an extension

I'm trying to capture and replace a filename like
000035 ZSMS_1.mp3
but also a file like
000035 1OMNA
(I'm basically trying to reorder them so they look like e.g., ZSMS_1(000035).mp3).
I've tried
^(\d+) (.*)(\..*$)?
^(\d+) (.*?)(\..*$)?
What I expect to happen:
000035 ZSMS_1.mp3:
[
{
"groups": [
"000035",
"ZSMS_1",
".mp3"
],
"match": "000035 ZSMS_1.mp3"
}
]
000035 1OMNA:
[
{
"groups": [
"000035",
"1OMNA",
""
],
"match": "000035 1OMNA"
}
]
What happens:
1.
^(\d+) (.*)(\..*$)?
000035 ZSMS_1.mp3:
[
{
"groups": [
"000035",
"ZSMS_1.mp3",
""
],
"match": "000035 ZSMS_1.mp3"
}
]
000035 1OMNA:
[
{
"groups": [
"000035",
"1OMNA",
""
],
"match": "000035 1OMNA"
}
]
^(\d+) (.*?)(\..*$)?
000035 ZSMS_1.mp3:
[
{
"groups": [
"000035",
"",
""
],
"match": "000035 "
}
]
000035 1OMNA:
[
{
"groups": [
"000035",
"",
""
],
"match": "000035 "
}
]
You may use
^(\d+)\h+(.*?)(\.[^.]*)?$
See the regex demo
Details
^ - start of string
(\d+) - Group 1: one or more digits
\h+ - 1+ horizontal whitespaces (for better regex engine cross-compatibility, you may use [^\S\r\n]+ or just [ \t]+ to match a tab or space)
(.*?) - Group 2: zero or more chars other than linebreak chars, as few as possible
(\.[^.]*)? - an optional capturing group #3: a dot and then 0 or more chars other than . as many as possible
$ - end of string.
You could try following regex:
^(\d+)\s*(?:(\w+)?)(?:(\.\w+)?)$
Details:
^ - start of line
(\d+) - Group 1: matches a digit
\s* - separates group 1 and 2
(?:(\w+)?) - Group 2 (optional): matches any word character
(?:(\.\w+)?) - Group 3 (optional): matches the character . and any word character
$ - end of line
Demo

Grok pattern with this log line

basically I need to filter out Date - SEVERITY - JAVACLASSNAME - ERROR MESSAGE.
This is working for me..But its just half done.
(?[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2},[0-9]{3}) %{WORD:Severity}(?:%{GREEDYDATA:msg})
It doesnt show Javaclass..!
Here is the output I get
{
"Timestamp": [
[
"2015-03-03 03:12:16,978"
]
],
"Severity": [
[
"INFO"
]
],
"Error_Message": [
[
" [http-bio-16006-exec-71] [XYZ.ABC.JLM.app.task.ERT] [app:/saas reqid:23121221 jsid:* aid:* uid: org: vorg: un:] - Received to update queued for monitorId=54213213JBNJBSJBSJBS, worklow=8u298u2189u312, session=21684216814321"
]
]
}
LOGLINE
2015-03-03 03:12:16,978 INFO [http-bio-16006-exec-71] [XYZ.ABC.JLM.app.task.ERT] [app:/saas reqid:23121221 jsid:* aid:* uid: org: vorg: un:] - Received to update queued for monitorId=54213213JBNJBSJBSJBS, worklow=8u298u2189u312, session=21684216814321
This should work:
filter {
grok {
match => [
"message",
"%{TIMESTAMP_ISO8601:timestamp} %{LOGLEVEL:severity} \[(?<threadname>[^\]]+)\] \[(?<classname>[^\]]+)\] %{GREEDYDATA:message}"
]
overwrite => ["message"]
}
}

To split a json file.. Extracting data between curly braces

I have a json file. I want to split that file into different parts..
Following is my file's content.
I want to split the content based on the curly brackets {},
"1010320": {
"abc": [
"1012220",
"hiiiiiiiii."
],
"xyz": "Describe"
},
"1012757": {
"pqr": [
"1013757",
"x"
]
},
"1014220": {
"abc": [
"1018420",
"sooooo"
],
"answer": "4th"
},
"1019660": {
"abc": [
"1031920",
"welcome"
],
"xyz": "Describing&Interpreting"
},
"1034280": {
"abc": [
"1040560",
"Ok..."
],
"nop": "Student Question"
},
The output should be:
1) "abc": [
"1012220",
"hiiiiiiiii."
],
"xyz": "Describe"
2) "pqr": [
"1013757",
"x"
]
3) "abc": [
"1018420",
"sooooo"
],
"answer": "4th"
plz.. help..
i think this will be useful for you
(?<=\{)\n\s+((?:[\n]+|.*)+?)\n\}
regex demo here : http://regex101.com/r/rS3wI5