Solved

Use request curl to configure

  • 13 June 2022
  • 2 replies
  • 143 views

Badge +3

Hello,

 

In version 21.10, we use the "centreon_token" to authenticate ourselves and perform curl commands to automate the configuration.

In 22.04, centreon_token is no longer available. The only way I found to enable auto discovery module:

 

authToken:

curl -k -d “username=admin&password=toto” -H “Content-Type:application/x-www-form-urlencoded” -X POST https://my_server/centreon/api/index.php?action=authenticate

{“authToken”:”YZJBg0VDQkp9pUJDyKgSP7cJT34J7BjICWB2GlOIDO6xX18uWIMBTg3LgWHhawoN”}

enable auto discovery module:

curl -v -k “https://my_server/centreon/api/internal.php?object=centreon_module&action=install&id=centreon-autodiscovery-server&type=module” -H "Content-Type:application/json" -H "X-AUTH-TOKEN:"YZJBg0VDQkp9pUJDyKgSP7cJT34J7BjICWB2GlOIDO6xX18uWIMBTg3LgWHhawoN""

 

*   Trying @IP my_server...
* TCP_NODELAY set
* Connected to my_server(@IP my_server..) 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, Certificate (11):
* TLSv1.3 (IN), TLS handshake, [no 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, [no content] (0):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: O=XXXX; CN=xxxxxx
*  start date: Jun  9 16:48:42 2022 GMT
*  expire date: Jun  8 16:48:42 2025 GMT
*  issuer: C=xxxxxxx
*  SSL certificate verify ok.
* TLSv1.3 (OUT), TLS app data, [no content] (0):
> GET /centreon/api/internal.php?object=centreon_module&action=install&id=centreon-autodiscovery-server&type=module HTTP/1.1
> Host: my_server
> User-Agent: curl/7.61.1
> Accept: */*
> Content-Type:application/json
> X-AUTH-TOKEN:YZJBg0VDQkp9pUJDyKgSP7cJT34J7BjICWB2GlOIDO6xX18uWIMBTg3LgWHhawoN

* TLSv1.3 (IN), TLS handshake, [no 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, [no content] (0):
< HTTP/1.1 401 Unauthorized
< Date: Mon, 13 Jun 2022 13:43:29 GMT
< Server:  
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate
< Pragma: no-cache
< Set-Cookie: PHPSESSID=739qv46m1i5j7m3n9vm9o3te4u; path=/;HttpOnly
< X-Frame-Options: sameorigin
< Transfer-Encoding: chunked
< Content-Type: application/json;charset=utf-8

* Connection #0 to host my_server left intact
"Unauthorized"

 

I don’t understand with i have Unauthorized…

Thank you

icon

Best answer by ponchoh 15 June 2022, 20:13

View original

2 replies

Badge +10

Hi @Cyril_31, have you tried with some 🍪's:

curl -X POST "http://localhost/centreon/api/latest/authentication/providers/configurations/local" -H "Content-Type: application/json" -H "Accept: application/json" -d '{"login":"admin","password": "superlongpropagandathatnoneonecanbreakinaweekbeforeitchangestosomethingelse.2"}' -c cookie.txt -b cookie.txt

you can see what goes in there (coookie.txt) and use that..


curl -X POST "http://localhost/centreon/api/internal.php?object=centreon_module&action=install&id=centreon-autodiscovery-server&type=module" -H "Accept: application/json" -b cookie.txt

FTR This is not an intended use, and could break things. Good luck!

Badge +3

Thank you !

Reply