Solved

cloud::google::gcp::management::stackdriver::plugin Field filter had an invalid value

  • 19 March 2024
  • 4 replies
  • 42 views

Badge +1


Hi,
I'm trying to collect some metrics from Google Compute APIs but cannot figure out how to use the plugin.
I got error code 400, maybe my filters are wrong...

## How to reproduce

- **Environment**:
result of `uname -a ; cat /etc/redhat-release /etc/debian_version`:

```
Linux server.domain 4.18.0-477.21.1.el8_8.x86_64 #1 SMP Thu Jul 20 08:38:27 EDT 2023 x86_64 x86_64 x86_64 GNU/Linux
Red Hat Enterprise Linux release 8.8 (Ootpa)
```

- **Version of the plugin**: `20240311-143354.el8`
- **Information about the monitored resource**: Google API
- **Command line**:

```
./centreon_gcp_management_stackdriver_api.pl \
  --plugin=cloud::google::gcp::management::stackdriver::plugin \
  --mode=get-metrics \
  --key-file=key.json \
  --dimension-name=metrics.labels.instance_name \
  --dimension-operator=equals \
  --dimension-value=NAME \
  --metric=instance/cpu/utilization \
  --api=compute.googleapis.com \
  --warning-metric=90 \
  --critical-metric=95 \
  --verbose \
  --proxyurl=http://proxy.domain:9090 \
  --http-backend=curl \
  --insecure \
  --debug
```

 

## Expected result

Some metrics...

## Actual result

 

```
UNKNOWN: Monitoring endpoint API return error code '400' (add --debug option for detailed message)
== Info:   Trying proxy.domain...
== Info: TCP_NODELAY set
== Info: Connected to proxy.domain (proxy.domain) port 9090 (#0)
== Info: allocate connect buffer!
== Info: Establish HTTP proxy tunnel to www.googleapis.com:443
=> Send header: CONNECT www.googleapis.com:443 HTTP/1.1
Host: www.googleapis.com:443
Proxy-Connection: Keep-Alive
=> Recv header: HTTP/1.0 200 Connection established
=> Recv header:
== Info: Proxy replied 200 to CONNECT request
== Info: CONNECT phase completed!
== Info: ALPN, offering http/1.1
== Info: successfully set certificate verify locations:
== Info:   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
== Info: TLSv1.3 (OUT), TLS handshake, Client hello (1):
== Info: CONNECT phase completed!
== Info: CONNECT phase completed!
== Info: TLSv1.3 (IN), TLS handshake, Server hello (2):
== Info: TLSv1.3 (IN), TLS handshake, [no content] (0):
== Info: TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
== Info: TLSv1.3 (IN), TLS handshake, Certificate (11):
== Info: TLSv1.3 (IN), TLS handshake, CERT verify (15):
== Info: TLSv1.3 (IN), TLS handshake, Finished (20):
== Info: TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
== Info: TLSv1.3 (OUT), TLS handshake, [no content] (0):
== Info: TLSv1.3 (OUT), TLS handshake, Finished (20):
== Info: SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
== Info: ALPN, server accepted to use http/1.1
== Info: Server certificate:
== Info:  subject: CN=upload.video.google.com
== Info:  start date: Feb 19 08:18:43 2024 GMT
== Info:  expire date: May 13 08:18:42 2024 GMT
== Info:  issuer: C=US; O=Google Trust Services LLC; CN=GTS CA 1C3
== Info:  SSL certificate verify ok.
== Info: TLSv1.3 (OUT), TLS app data, [no content] (0):
=> Send header: POST /oauth2/v4/token HTTP/1.1
Host: www.googleapis.com
Accept:application/json
Content-Type: application/x-www-form-urlencoded
Content-Length: 746
=> Send data: assertion=xxxxx
== Info: upload completely sent off: 746 out of 746 bytes
== Info: TLSv1.3 (IN), TLS handshake, [no content] (0):
== Info: TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
== Info: TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
== Info: TLSv1.3 (IN), TLS app data, [no content] (0):
=> Recv header: HTTP/1.1 200 OK
=> Recv header: Content-Type: application/json; charset=UTF-8
=> Recv header: Vary: X-Origin
=> Recv header: Vary: Referer
=> Recv header: Date: Tue, 19 Mar 2024 14:08:37 GMT
=> Recv header: Server: scaffolding on HTTPServer2
=> Recv header: Cache-Control: private
=> Recv header: X-XSS-Protection: 0
=> Recv header: X-Frame-Options: SAMEORIGIN
=> Recv header: X-Content-Type-Options: nosniff
=> Recv header: Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
=> Recv header: Accept-Ranges: none
=> Recv header: Vary: Origin,Accept-Encoding
=> Recv header: Transfer-Encoding: chunked
=> Recv header:
=> Recv data: 43b
{"access_token":"xxxxx
== Info: TLSv1.3 (IN), TLS app data, [no content] (0):
=> Recv data: xxxxx"}
== Info: TLSv1.3 (IN), TLS app data, [no content] (0):
=> Recv data: 0
== Info: Connection #0 to host proxy.domain left intact
== Info: Found bundle for host monitoring.googleapis.com: 0x55d4ba7b8d30 [can pipeline]
== Info: Hostname proxy.domain was found in DNS cache
== Info:   Trying proxy.domain...
== Info: TCP_NODELAY set
== Info: Connected to proxy.domain (proxy.domain) port 9090 (#1)
== Info: allocate connect buffer!
== Info: Establish HTTP proxy tunnel to monitoring.googleapis.com:443
=> Send header: CONNECT monitoring.googleapis.com:443 HTTP/1.1
Host: monitoring.googleapis.com:443
Proxy-Connection: Keep-Alive
=> Recv header: HTTP/1.0 200 Connection established
=> Recv header:
== Info: Proxy replied 200 to CONNECT request
== Info: CONNECT phase completed!
== Info: ALPN, offering http/1.1
== Info: successfully set certificate verify locations:
== Info:   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
== Info: TLSv1.3 (OUT), TLS handshake, Client hello (1):
== Info: CONNECT phase completed!
== Info: CONNECT phase completed!
== Info: TLSv1.3 (IN), TLS handshake, Server hello (2):
== Info: TLSv1.3 (IN), TLS handshake, [no content] (0):
== Info: TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
== Info: TLSv1.3 (IN), TLS handshake, Certificate (11):
== Info: TLSv1.3 (IN), TLS handshake, CERT verify (15):
== Info: TLSv1.3 (IN), TLS handshake, Finished (20):
== Info: TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
== Info: TLSv1.3 (OUT), TLS handshake, [no content] (0):
== Info: TLSv1.3 (OUT), TLS handshake, Finished (20):
== Info: SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
== Info: ALPN, server accepted to use http/1.1
== Info: Server certificate:
== Info:  subject: CN=edgecert.googleapis.com
== Info:  start date: Feb 19 08:23:29 2024 GMT
== Info:  expire date: May 13 08:23:28 2024 GMT
== Info:  issuer: C=US; O=Google Trust Services LLC; CN=GTS CA 1C3
== Info:  SSL certificate verify ok.
== Info: TLSv1.3 (OUT), TLS app data, [no content] (0):
=> Send header: GET /v3/projects/prj-isp-netq0-iaas-test-001/timeSeries/?filter=metric.type+%3D+%22compute.googleapis.com%2Finstance%2Fcpu%2Futilization%22+AND+metrics.labels.instance_name+%3D+%22NAME%22&interval.endTime=2024-03-19T14%3A08%3A37.000000Z&interval.startTime=2024-03-19T13%3A58%3A37.000000Z HTTP/1.1
Host: monitoring.googleapis.com
Accept:application/json
Authorization:Bearer xxxxx
== Info: TLSv1.3 (IN), TLS handshake, [no content] (0):
== Info: TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
== Info: TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
== Info: TLSv1.3 (IN), TLS app data, [no content] (0):
=> Recv header: HTTP/1.1 400 Bad Request
=> Recv header: Vary: X-Origin
=> Recv header: Vary: Referer
=> Recv header: Content-Type: application/json; charset=UTF-8
=> Recv header: Date: Tue, 19 Mar 2024 14:08:37 GMT
=> Recv header: Server: ESF
=> Recv header: Cache-Control: private
=> Recv header: X-XSS-Protection: 0
=> Recv header: X-Frame-Options: SAMEORIGIN
=> Recv header: X-Content-Type-Options: nosniff
=> Recv header: Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
=> Recv header: Accept-Ranges: none
=> Recv header: Vary: Origin,Accept-Encoding
=> Recv header: Transfer-Encoding: chunked
=> Recv header:
=> Recv data: 16b
{
  "error": {
    "code": 400,
    "message": "Field filter had an invalid value of \"metric.type = \"compute.googleapis.com/instance/cpu/utilization\" AND metrics.labels.instance_name = \"NAME\"\": The lefthand side of each expression must be prefixed with one of {group, metadata, metric, project, resource}.",
    "status": "INVALID_ARGUMENT"
  }
}
== Info: TLSv1.3 (IN), TLS app data, [no content] (0):
=> Recv data: 0
== Info: Connection #1 to host proxy.domain left intact
Error message : Field filter had an invalid value of "metric.type = "compute.googleapis.com/instance/cpu/utilization" AND metrics.labels.instance_name = "NAME"": The lefthand side of each expression must be prefixed with one of {group, metadata, metric, project, resource}.
```

Thanks in advance for any help,

 

icon

Best answer by christophe.niel-ACT 20 March 2024, 12:11

View original

4 replies

Userlevel 5
Badge +14

hello

just to be sure, did you run the command as displayed above ? (i’m guessing you replaced NAME with a real instance name.)

was there some single quote for each values as here in the documentation  : https://docs.centreon.com/pp/integrations/plugin-packs/procedures/cloud-gcp-management-stackdriver/#how-to-test-the-plugin-and-what-are-the-main-options-for

(there may be some automatic string conversion with double quoted string, and normally when using the service template from the plugin pack the single quotes are automatically used)

given the error returned by google says you should prefix with something and that something is there (prefix.) but with \” at the start and perl will automatically put double quotes on a string parameter, there may be some cause and effect here.

just an hypothesis, but if it’s not that, then I don’t know what’s happening 

 

best regards

Badge +1

Hi, thanks for the quick response.

 

just to be sure, did you run the command as displayed above ? (I’m guessing you replaced NAME with a real instance name.)

was there some single quote for each values as here in the documentation

 

Yes I’ve tried both single and double quotes, with or without ‘=’ operator, got same results..

--flag="argument"
--flag "argument"
--flag='argument'
--flag 'argument'


Yes, NAME was replaced with the actual instance name.

Do you think is it appropriate to fill an issue on Github?

Userlevel 5
Badge +14

maybe not

maybe there was a change in the GCP api, or maybe it is something else, no idea (I don’t have any gcp resources to try this plugin)

you could also try to debug the api call by calling the google api from a software like postman or insomnia, 

 

if you look at your full log it says exactly the query used : 

GET /v3/projects/prj-isp-netq0-iaas-test-001/timeSeries/?filter=metric.type+%3D+%22compute.googleapis.com%2Finstance%2Fcpu%2Futilization%22+AND+metrics.labels.instance_name+%3D+%22NAME%22&interval.endTime=2024-03-19T14%3A08%3A37.000000Z&interval.startTime=2024-03-19T13%3A58%3A37.000000Z

this translate to 

GET/v3/projects/prj-isp-netq0-iaas-test-001/timeSeries/?filter=metric.type+=+"compute.googleapis.com/instance/cpu/utilization"+AND+metrics.labels.instance_name+=+"NAME"&interval.endTime=2024-03-19T14:08:37.000000Z&interval.startTime=2024-03-19T13:58:37.000000Z

 

edit:

and as I was typing this i see what you may have done wrong, the error from google is not happy with the “lefthand” part of the filters and look at the example I linked above

and what you passed in the argument

i’m guessing the “s” in metric may not be ok, but i can’t test it

 

if the additionnal s in metrics is not the issue, it may come from the quotation marks, that you can test buy using insomnia or postman and passing your api key on that “GET” url

Badge +1

edit:

and as I was typing this i see what you may have done wrong, the error from google is not happy with the “lefthand” part of the filters and look at the example I linked above

and what you passed in the argument

i’m guessing the “s” in metric may not be ok, but i can’t test it

 

That was a typo and of course as I corrected it, it works now!
Thank you very much!

Reply