input:
[{
"{#SNMPINDEX}": "2",
"{#SNAPSHOT}": "nodename/.snapshot"
}]
regEx:
$..[?(@.['{#SNAPSHOT}'] =~ ".snapshot")]
[
{
"TABLESPACE": "SYSTEM",
"CONTAINER": "BLAH",
"USEDMAXSIZE": "1.56"
},
{
"TABLESPACE": "ANOTHER",
"CONTAINER": "YES",
"USEDMAXSIZE": ".06"
}
]
JSONPATH:
$..[?(@.TABLESPACE == "SYSTEM")]
If node name contains spaces:
$..[?(@.["TABLE SPACE"] == "SYSTEM")]
Multiple conditions:
$..[?(@.TABLESPACE == 'SYSTEM' && @.CONTAINER == 'BLAH')].USEDMAXSIZE
Best example:
[{
"Namespace": "AWS/EC2",
"Dimensions": [
{
"Name": "InstanceId",
"Value": "i-0ad4b6cfaf8da800f"
}
],
"MetricName": "CPUUtilization"
}]
$..[?(@.MetricName == 'CPUUtilization')].Dimensions..[?(@.Name == 'InstanceId')].Value
JSON:
{
"status": "success",
"data": {
"resultType": "vector",
"result": [{
"metric": {
"service": "name1",
"description": "warning"
},
"value": [
1574348636.712,
"1"
]
},
{
"metric": {
"service": "name2",
"description": "critical"
},
"value": [
1574348636.712,
"1"
]
},
{
"metric": {
"service": "name3",
"feature": "enabled",
"description": "critical"
},
"value": [
1574348636.712,
"1"
]
}
]
}
}
Search if CustomValue exist:
$.data.result..[?(@.service == 'name3')].feature
Simpler example, input:
[{
"metric": {
"service": "name1",
"description": "warning"
},
"value": [
1574348636.712,
"1"
]
}, {
"metric": {
"service": "name2",
"description": "critical"
},
"value": [
1574348636.712,
"1"
]
}, {
"metric": {
"service": "name3",
"feature": "enabled",
"description": "critical"
},
"value": [
1574348636.712,
"1"
]
}]
Path:
$..[?(@.service == 'name3')].feature
Another example, input data:
[{
"metric": {
"instance": "asdf"
},
"value": [1623406495.508, "1"]
},
{
"metric": {
"instance": "ghjk"
},
"value": [1623406495.508, "1"]
}
]
JSON path to extract value:
$.[?(@.metric.instance == "asdf")]
Input:
{
"kh1g4cnndq4l": {
"component": {
"code": "kh1g4cnndq4l",
"name": "User Authentication"
},
"days": [
{
"date": "2011-12-02",
"outages": {},
"related_events": []
}
]
},
"7gf9x664hrfj": {
"component": {
"code": "7gf9x664hrfj",
"name": "Services Authentication"
},
"days": [
{
"date": "2021-12-02",
"outages": {},
"related_events": []
}
]
}
}
JSONPath:
$.[?(@.component.name == 'User Authentication')]
No comments:
Post a Comment