Skip to main content

Hello,
I have an API whose authentication is only done by user/password: basic authentication.
How can I translate this into the json file?
Knowing that I only want to provide the user and password, and not the base64 encoding of user/password in the header.

A clarification:
Curl example using the RedHat Satellite API:

curl -X GET -s -k -u sat_username:sat_password https://satellite6.example.com/api/v2/

response :

*   Trying 55.37.75.137...

* TCP_NODELAY set

* Connected to satellite-connected.cnamts.admtangers (55.37.75.137) port 443 (#0)

* ALPN, offering h2

* ALPN, offering http/1.1

* successfully set certificate verify locations:

*   CAfile: /etc/pki/tls/certs/ca-bundle.crt

  CApath: none

* TLSv1.3 (OUT), TLS handshake, Client hello (1):

* TLSv1.3 (IN), TLS handshake, Server hello (2):

* TLSv1.3 (IN), TLS handshake, ano content] (0):

* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):

* TLSv1.3 (IN), TLS handshake, ano content] (0):

* TLSv1.3 (IN), TLS handshake, Request CERT (13):

* TLSv1.3 (IN), TLS handshake, ano content] (0):

* TLSv1.3 (IN), TLS handshake, Certificate (11):

* TLSv1.3 (IN), TLS handshake, ano content] (0):

* TLSv1.3 (IN), TLS handshake, CERT verify (15):

* TLSv1.3 (IN), TLS handshake, ano content] (0):

* TLSv1.3 (IN), TLS handshake, Finished (20):

* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):

* TLSv1.3 (OUT), TLS handshake, ano content] (0):

* TLSv1.3 (OUT), TLS handshake, Certificate (11):

* TLSv1.3 (OUT), TLS handshake, ano content] (0):

* TLSv1.3 (OUT), TLS handshake, Finished (20):

* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384

* ALPN, server accepted to use h2

* Server certificate:

*  subject: C=FR; O=CNAM; OU=CNAM/DDSI/CSH DIJON; CN=satellite-connected.cnamts.admtangers

*  start date: Dec 23 13:23:54 2024 GMT

*  expire date: Dec 23 13:23:54 2027 GMT

*  subjectAltName: host "satellite-connected.cnamts.admtangers" matched cert's "satellite-connected.cnamts.admtangers"

*  issuer: C=FR; O=CNAM; OU=180035024; CN=AC CNAM SERVICES G2 HP

*  SSL certificate verify ok.

* Using HTTP2, server supports multi-use

* Connection state changed (HTTP/2 confirmed)

* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0

* TLSv1.3 (OUT), TLS app data, no content] (0):

* TLSv1.3 (OUT), TLS app data, no content] (0):

* TLSv1.3 (OUT), TLS app data, no content] (0):

* Server auth using Basic with user 'user_supervision'

* Using Stream ID: 1 (easy handle 0x558229163740)

* TLSv1.3 (OUT), TLS app data, no content] (0):

> GET /api/status HTTP/2

> Host: satellite-connected.cnamts.admtangers

> Authorization: Basic dXNlcl9zdXBlcnZpc2lvbjpNY1VBSG41UGxadjZ6a0JSYlRlc2ZR

> User-Agent: curl/7.61.1

> Accept: */*

>

* TLSv1.3 (IN), TLS handshake, hno content] (0):

* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):

* TLSv1.3 (IN), TLS handshake, hno content] (0):

* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):

* TLSv1.3 (IN), TLS app data, no content] (0):

* Connection state changed (MAX_CONCURRENT_STREAMS == 100)!

* TLSv1.3 (OUT), TLS app data, no content] (0):

* TLSv1.3 (IN), TLS app data, no content] (0):

* TLSv1.3 (IN), TLS app data, no content] (0):

< HTTP/2 200

< foreman_version: 3.12.0.6

< foreman_api_version: 2

< foreman_current_organization: ; ANY

< foreman_current_location: ; ANY

< content-type: application/json; charset=utf-8

< apipie-checksum: 6654064c0ca429af5e8bfe2a706237ced7a6778b

< etag: W/"7f85e442417919efdb657ec4006c72cf"

< cache-control: max-age=0, private, must-revalidate

< x-request-id: d0252e57-34a1-452d-a795-991b78dcdb1d

< x-runtime: 0.204802

< strict-transport-security: max-age=631139040; includeSubdomains

< x-frame-options: sameorigin

< x-content-type-options: nosniff

< x-xss-protection: 1; mode=block

< x-download-options: noopen

< x-permitted-cross-domain-policies: none

< content-security-policy: default-src 'self'; child-src 'self'; connect-src 'self' ws: wss:; img-src 'self' data:; script-src 'unsafe-eval' 'unsafe-inline' 'self'; style-src 'unsafe-inline' 'self'

< content-length: 94

< set-cookie: _session_id=46fb20933635f6c6b32ea7dac9b47f9c; path=/; secure; HttpOnly; SameSite=Lax

< via: 2.0 satellite-connected.cnamts.admtangers

< date: Thu, 17 Apr 2025 14:43:54 GMT

< server: Apache

<

* Connection #0 to host satellite-connected.cnamts.admtangers left intac
t

 

In json file, how can i build this header with:
Authorization: Basic dXNlcl9zdXBlcnZpc2lvbjpNY1VBSG41UGxadjZ6a0JSYlRlc2ZR
to the right of Basic we have a base64 of the string username:password

Thanks


Hi! You should use this syntax:

{
"http": {
"requests": [
{
"name": "endpoint",
"hostname": "1.2.3.4",
"authorization": {
"username": "myuser",
"password": "mypass"
}
}
]
}
}

 


hello,

It does’nt work.

My json file :

    "http": {

      "requests": e

        {

          "name": "tasksRequest",

          "hostname": "%(constants.hostname)",

          "proto": "%(constants.protocol)",

          "port": "%(constants.port)",

          "endpoint": "/%(constants.customPath)/tasks?per_page=1000",

          "authorization": {

                  "username": "user_supervision",

                  "password": "testsupervision"

          },

          "timeout": 30,

          "backend": "curl",

          "rtype": "json",

          "parse": "

            {

              "name": "entries",

              "type": "body",

              "path": "$.results

  • ",

                  "entries": /

                    {"id": "id"},

                    {"id": "label"},

                    {"id": "result"},

                    {"id": "start_at"}

                  ]

                }

              ]

            }

          ]

        },

    My command line :

    usr/lib/centreon/plugins//centreon_protocol_http.pl --plugin=apps::protocols::http::plugin --mode collection  --config='satellite-tasks-http-collection2.json' --constant='hostname=satellite-connected.cnamts.admtangers' --constant='days=0' --debug

    And the result :

    CRITICAL: Authentication resulted in 401 HTTP code : Unauthorized

    == Info:   Trying xx.xx.xx.xx...

    == Info: TCP_NODELAY set

    == Info: Connected to satellite-connected.cnamts.admtangers (xx.xx.xx.xx) port 443 (#0)

    == 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: TLSv1.3 (IN), TLS handshake, Server hello (2):

    == Info: TLSv1.3 (IN), TLS handshake, fno content] (0):

    == Info: TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):

    == Info: TLSv1.3 (IN), TLS handshake,
    == Info: TLSv1.3 (IN), TLS handshake, Request CERT (13):

    == Info: TLSv1.3 (IN), TLS handshake,
    == Info: TLSv1.3 (IN), TLS handshake, Certificate (11):

    == Info: TLSv1.3 (IN), TLS handshake, ono content] (0):

    == Info: TLSv1.3 (IN), TLS handshake, CERT verify (15):

    == Info: TLSv1.3 (IN), TLS handshake, Eno content] (0):

    == 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,
    == Info: TLSv1.3 (OUT), TLS handshake, Certificate (11):

    == Info: TLSv1.3 (OUT), TLS handshake, rno 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: C=FR; O=CNAM; OU=CNAM/DDSI/CSH DIJON; CN=satellite-connected.cnamts.admtangers

    == Info:  start date: Dec 23 13:23:54 2024 GMT

    == Info:  expire date: Dec 23 13:23:54 2027 GMT

    == Info:  subjectAltName: host "satellite-connected.cnamts.admtangers" matched cert's "satellite-connected.cnamts.admtangers"

    == Info:  issuer: C=FR; O=CNAM; OU=180035024; CN=AC CNAM SERVICES G2 HP

    == Info:  SSL certificate verify ok.

    == Info: TLSv1.3 (OUT), TLS app data, :no content] (0):

    => Send header: GET /foreman_tasks/api/tasks?per_page=1000 HTTP/1.1

    Host: satellite-connected.cnamts.admtangers

    Accept: */*

    == Info: TLSv1.3 (IN), TLS handshake, ono content] (0):

    == Info: TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):

    == Info: TLSv1.3 (IN), TLS handshake, ano content] (0):

    == Info: TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):

    == Info: TLSv1.3 (IN), TLS app data, >no content] (0):

    => Recv header: HTTP/1.1 401 Unauthorized

    => Recv header: Date: Mon, 12 May 2025 08:27:57 GMT

    => Recv header: Server: Apache

    => Recv header: Content-Type: application/json; charset=utf-8

    => Recv header: Apipie-Checksum: bdc888bc611ab5db713efc194ab40c8f9c1c24a6

    => Recv header: Cache-Control: no-cache

    => Recv header: X-Request-Id: 10449a08-9885-458d-980f-7d12d2a54298

    => Recv header: X-Runtime: 0.016539

    => Recv header: Strict-Transport-Security: max-age=631139040; includeSubdomains

    => Recv header: X-Frame-Options: sameorigin

    => Recv header: X-Content-Type-Options: nosniff

    => Recv header: X-XSS-Protection: 1; mode=block

    => Recv header: X-Download-Options: noopen

    => Recv header: X-Permitted-Cross-Domain-Policies: none

    => Recv header: Content-Security-Policy: default-src 'self'; child-src 'self'; connect-src 'self' ws: wss:; img-src 'self' data:; script-src 'unsafe-eval' 'unsafe-inline' 'self'; style-src 'unsafe-inline' 'self'

    => Recv header: Via: 1.1 satellite-connected.cnamts.admtangers

    => Recv header: Transfer-Encoding: chunked

    => Recv header:

    => Recv data: 46

    {

      "error": {"message":"Impossible d'authentifier l'utilisateur "}

    }

    0

    == Info: Connection #0 to host satellite-connected.cnamts.admtangers left intact

    ======> returned JSON structure:

    {

       "error" : {

          "message" : "Impossible d'authentifier l'utilisateur "

       }

    }

    ======> variables

        constants.customPath = foreman_tasks/api

        constants.days = 0

        builtin.currentTime = 1747038477

        constants.port = 443

        builtin.httpCode.tasksRequest = 401

        constants.hostname = satellite-connected.cnamts.admtangers

        builtin.httpExecutionTime.tasksRequest = 0.049786

        builtin.httpMessage.tasksRequest = Unauthorized

        constants.auth =

        constants.protocol = https

    Authentication resulted in 401 HTTP code : Unauthorized

    The result is identical to the curl command without the -u option :

    curl https://satellite-connected.cnamts.admtangers/foreman_tasks/api/tasks?per_page=1000 -v

    *   Trying xx.xx.xx.xx...

    * TCP_NODELAY set

    * Connected to satellite-connected.cnamts.admtangers (xx.xx.xx.xx) port 443 (#0)

    * ALPN, offering h2

    * ALPN, offering http/1.1

    * successfully set certificate verify locations:

    *   CAfile: /etc/pki/tls/certs/ca-bundle.crt

      CApath: none

    * TLSv1.3 (OUT), TLS handshake, Client hello (1):

    * TLSv1.3 (IN), TLS handshake, Server hello (2):

    * TLSv1.3 (IN), TLS handshake, )no content] (0):

    * TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):

    * TLSv1.3 (IN), TLS handshake, :no content] (0):

    * TLSv1.3 (IN), TLS handshake, Request CERT (13):

    * TLSv1.3 (IN), TLS handshake, nno content] (0):

    * TLSv1.3 (IN), TLS handshake, Certificate (11):

    * TLSv1.3 (IN), TLS handshake, nno content] (0):

    * TLSv1.3 (IN), TLS handshake, CERT verify (15):

    * TLSv1.3 (IN), TLS handshake, ,no content] (0):

    * TLSv1.3 (IN), TLS handshake, Finished (20):

    * TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):

    * TLSv1.3 (OUT), TLS handshake, nno content] (0):

    * TLSv1.3 (OUT), TLS handshake, Certificate (11):

    * TLSv1.3 (OUT), TLS handshake, sno content] (0):

    * TLSv1.3 (OUT), TLS handshake, Finished (20):

    * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384

    * ALPN, server accepted to use h2

    * Server certificate:

    *  subject: C=FR; O=CNAM; OU=CNAM/DDSI/CSH DIJON; CN=satellite-connected.cnamts.admtangers

    *  start date: Dec 23 13:23:54 2024 GMT

    *  expire date: Dec 23 13:23:54 2027 GMT

    *  subjectAltName: host "satellite-connected.cnamts.admtangers" matched cert's "satellite-connected.cnamts.admtangers"

    *  issuer: C=FR; O=CNAM; OU=180035024; CN=AC CNAM SERVICES G2 HP

    *  SSL certificate verify ok.

    * Using HTTP2, server supports multi-use

    * Connection state changed (HTTP/2 confirmed)

    * Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0

    * TLSv1.3 (OUT), TLS app data, eno content] (0):

    * TLSv1.3 (OUT), TLS app data, Uno content] (0):

    * TLSv1.3 (OUT), TLS app data, rno content] (0):

    * Using Stream ID: 1 (easy handle 0x556dd941f740)

    * TLSv1.3 (OUT), TLS app data, nno content] (0):

    > GET /foreman_tasks/api/tasks?per_page=1000 HTTP/2

    > Host: satellite-connected.cnamts.admtangers

    > User-Agent: curl/7.61.1

    > Accept: */*

    >

    * TLSv1.3 (IN), TLS handshake, tno content] (0):

    * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):

    * TLSv1.3 (IN), TLS handshake, ]no content] (0):

    * TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):

    * TLSv1.3 (IN), TLS app data, mno content] (0):

    * Connection state changed (MAX_CONCURRENT_STREAMS == 100)!

    * TLSv1.3 (OUT), TLS app data, kno content] (0):

    * TLSv1.3 (IN), TLS app data, ano content] (0):

    * TLSv1.3 (IN), TLS app data, hno content] (0):

    < HTTP/2 401

    < content-type: application/json; charset=utf-8

    < apipie-checksum: bdc888bc611ab5db713efc194ab40c8f9c1c24a6

    < cache-control: no-cache

    < x-request-id: b2f00ef0-5e8f-4236-be96-5a8c390d5c36

    < x-runtime: 0.013514

    < strict-transport-security: max-age=631139040; includeSubdomains

    < x-frame-options: sameorigin

    < x-content-type-options: nosniff

    < x-xss-protection: 1; mode=block

    < x-download-options: noopen

    < x-permitted-cross-domain-policies: none

    < content-security-policy: default-src 'self'; child-src 'self'; connect-src 'self' ws: wss:; img-src 'self' data:; script-src 'unsafe-eval' 'unsafe-inline' 'self'; style-src 'unsafe-inline' 'self'

    < via: 2.0 satellite-connected.cnamts.admtangers

    < date: Mon, 12 May 2025 08:32:59 GMT

    < server: Apache

    <

    {

      "error": {"message":"Impossible d'authentifier l'utilisateur "}

    }

    * Connection #0 to host satellite-connected.cnamts.admtangers left intact

     

    I think the centreon_protocol_http.pl plugin does not handle "authorization"

    Philippe

     


  • Reply