Hello,
Let's say we have a prometheus json like this (the real one is a lot bigger) :
1) I'd like to retreive all the pods with the "namespace" field matching the regexp "openshift-.*", like this :
But none of these seem to be working :
While, with an exact namespace it works fine :
Result :
How can I filter json fields matching a regexp ?
2) Another solution is that I can also retreive all the pods with a "value" :"0", but in that case, I need to display the namespace AND the pod on the same line so that I can filter again with a simple regexp.
But this :
gives me this (namespace and pod on 2 lines) :
Any solution please ? Or is it a limitation of Zabbix jsonpath preprocessing ?
Let's say we have a prometheus json like this (the real one is a lot bigger) :
Code:
{
"status": "success",
"data": {
"resultType": "vector",
"result": [
{
"metric": {
"__name__": "kube_running_pod_ready",
"namespace": "argo-rollouts",
"pod": "argo-rollouts-6fdcf89f7c-mzxcl",
"prometheus": "openshift-monitoring/k8s"
},
"value": [
1641539963.261,
"1"
]
},
{
"metric": {
"__name__": "kube_running_pod_ready",
"namespace": "gitlab-runner",
"pod": "gitlab-runner-controller-manager-56b77757c-82wxh",
"prometheus": "openshift-monitoring/k8s"
},
"value": [
1641539963.261,
"1"
]
},
{
"metric": {
"__name__": "kube_running_pod_ready",
"namespace": "openshift-cluster-csi-drivers",
"pod": "ovirt-csi-driver-node-dlhz4",
"prometheus": "openshift-monitoring/k8s"
},
"value": [
1641539963.261,
"0"
]
},
{
"metric": {
"__name__": "kube_running_pod_ready",
"namespace": "openshift-toto-runner",
"pod": "kub-runner-1-runner-7c5c45d454-dvv6g",
"prometheus": "openshift-monitoring/k8s"
},
"value": [
1641539963.261,
"1"
]
}
]
}
}
1) I'd like to retreive all the pods with the "namespace" field matching the regexp "openshift-.*", like this :
Code:
[ "ovirt-csi-driver-node-dlhz4", "kub-runner-1-runner-7c5c45d454-dvv6g" ]
Code:
$.data.result.[?(@.namespace=~openshift-)].pod $.data.result.[?(@.namespace=~"openshift-.*")].pod $.data.result.[?(@.namespace=~"/^openshift-.*$/i")].pod
Code:
$.data.result.[?(@.namespace=="openshift-cluster-csi-drivers")].pod
Code:
[ "ovirt-csi-driver-node-dlhz4" ]
2) Another solution is that I can also retreive all the pods with a "value" :"0", but in that case, I need to display the namespace AND the pod on the same line so that I can filter again with a simple regexp.
But this :
Code:
$.data.result[?(@.value[1]=="0")].metric.[namespace,pod]
Code:
[ "openshift-cluster-csi-drivers", "ovirt-csi-driver-node-dlhz4" ]
Comment