|
|
(3 révisions intermédiaires par 2 utilisateurs non affichées) |
Ligne 1 : |
Ligne 1 : |
| ==Généralités== | | ==Généralités== |
| + | <br> |
| + | {{Warning | Avant toutes choses, n'allez pas plus loin si vous n'avez pas lu la section [[DbSQWare:Concepts|"Concepts dbSQWare"]] !}} |
| | | |
| ===Limites de cette section=== | | ===Limites de cette section=== |
| Cette section n’a pas la prétention de traiter tous les cas possibles de paramétrage de dbSQWare.<br> | | Cette section n’a pas la prétention de traiter tous les cas possibles de paramétrage de dbSQWare.<br> |
| Avant de dire « ça ne fonctionne pas », lisez bien le message d’erreur et réfléchissez à ce dont vous avez besoin au niveau du socle pour que les scripts fonctionnent. Par exemple, si vous n’arrivez pas à faire un sqlplus en ligne de commande pour vous connecter à votre instance Oracle, il n’y a pas de raison pour que les scripts arrivent à le faire (il n’y a rien de magique) !<br> | | Avant de dire « ça ne fonctionne pas », lisez bien le message d’erreur et réfléchissez à ce dont vous avez besoin au niveau du socle pour que les scripts fonctionnent. Par exemple, si vous n’arrivez pas à faire un sqlplus en ligne de commande pour vous connecter à votre instance Oracle, il n’y a pas de raison pour que les scripts arrivent à le faire (il n’y a rien de magique) !<br> |
| + | <br> |
| + | Ce chapitre ne traite que de l'ajout d'une nouvelle instance sur un socle fonctionnel (pour l’installation du socle central, pour les autres paramétrages, reportez-vous aux sections adéquates).<br> |
| | | |
− | ===Paramétrage préalable=== | + | ===MODOP général d'intégration d'une nouvelle instance=== |
− | Afin de pouvoir utiliser l'API "update", vous devez au préalable avoir paramétré un login avec le type d'authentification "internal_api_update".
| + | Le principe est toujours plus ou moins le même ... |
| + | *Vérification des prérequis |
| + | *Mise en place de l'environnement |
| + | *Tests "manuels" |
| + | *Mise en exploitation de l'instance |
| + | Vous verrez que ces étapes peuvent être traitée une par une ou par paquet ! |
| | | |
− | ==Exemples d'utilisation== | + | ==Les SGBD== |
− | Vous devez adapter les exemples suivants avec vos propres données (URL, user, password, ...)<br/>
| + | Même si le principe est toujours le même, certains SGBD peuvent avoir une ou deux spécificités, c'est pour cela que nous les traiterons un par un ...<br/> |
− | Ceci représente une base pour du Python, PHP et shell.<br/>
| + | Si votre SGBD n'existe pas dans ce wiki, regardez ce que l'on fait pour MySQL et/ou PostgreSQL et adaptez les "racines", il y a de grandes chances que cela suffise.<br/> |
− | Vous pouvez bien évidemment utiliser le langage de votre choix.<br/>
| + | <br/> |
− | | + | [[Général:FAQ_NouvelleInstanceOracleOn|FAQ : Intégration d'une nouvelle instance Oracle]]<br/> |
− | ===Python===
| + | <br/> |
− | import requests
| + | [[Général:FAQ_NouvelleInstanceMySQL|FAQ : Intégration d'une nouvelle instance MySQL/MariaDB]]<br/> |
− | import json
| + | <br/> |
− |
| + | [[Général:FAQ_NouvelleInstancePostgreSQL|FAQ : Intégration d'une nouvelle instance PostgreSQL]]<br/> |
− | v_bearer_token = ""
| + | <br/> |
− |
| + | [[Général:FAQ_NouvelleInstanceMsSql| FAQ : Intégration d'une nouvelle instance Sql-Serveur Windows]]<br/> |
− | """
| + | <br/> |
− | f_api_request does API request
| + | [[Général:FAQ_NouvelleInstanceMsSql_Linux| FAQ : Intégration d'une nouvelle instance Sql-Serveur Linux]]<br/> |
− |
| + | <br/> |
− | :param v_method : request method
| + | [[Général:FAQ_NouvelleInstanceSybase|FAQ : Intégration d'une nouvelle instance Sybase]]<br/> |
− | :param v_url : website url
| + | <br/> |
− | :param t_headers : JSON object headers
| + | [[Général:FAQ_NouvelleInstanceMongoDB|FAQ : Intégration d'une nouvelle instance MongoDB]]<br/> |
− | :param t_data : JSON object data
| + | <br/> |
− | :return : API request return
| |
− | """
| |
− | def f_api_request(v_method, v_url, t_headers={}, t_data={}):
| |
− | v_response = requests.request(v_method, v_url, headers=t_headers, data=t_data) # API request
| |
− | return v_response
| |
− |
| |
− | """
| |
− | f_get_bearer_token recovers bearer token
| |
− |
| |
− | :param v_username : account username
| |
− | :param v_password : account password
| |
− | :return : bearer token
| |
− | """
| |
− | def f_get_bearer_token(v_username, v_password):
| |
− | v_method = "POST"
| |
− | v_url = "http://my_sqwareweb_url/lib/apiUpdate_login.php"
| |
− | t_headers = {'Content-Type': 'application/json'}
| |
− | t_data = json.dumps({"username":v_username,"password":v_password}) # Crendentials for connection
| |
− |
| |
− | v_response = f_api_request(v_method, v_url, t_headers=t_headers, t_data=t_data) # API request
| |
− | v_json_response = json.loads(v_response.text)
| |
− | if "error_message" not in v_json_response:
| |
− | global v_bearer_token
| |
− | v_bearer_token = v_json_response['results'][0]['token'] # Get token response
| |
− | print("Bearer token : "+v_bearer_token)
| |
− | return 1
| |
− | else:
| |
− | v_error_message = v_json_response['error_message']
| |
− | print("Error message ["+v_error_message+"]")
| |
− | return 0
| |
− |
| |
− | """
| |
− | f_get_instance recovers instance object
| |
− |
| |
− | :param v_dbalias : dbalias name
| |
− | :return : instance object
| |
− | """
| |
− | def f_get_instance(v_dbalias):
| |
− | v_method = "GET"
| |
− | v_url = "http://my_sqwareweb_url/lib/apiUpdate.php?dbalias="+v_dbalias
| |
− | t_headers = {'Authorization':'Bearer '+v_bearer_token, 'Content-Type': 'application/json'}
| |
− |
| |
− | v_response = f_api_request(v_method, v_url, t_headers=t_headers) # API request
| |
− | v_json_response = json.loads(v_response.text)
| |
− | if "error_message" not in v_json_response:
| |
− | v_instance = v_json_response['results'][0] # Get instance
| |
− | print(v_instance)
| |
− | return 1
| |
− | else:
| |
− | v_error_message = v_json_response['error_message']
| |
− | print("Error message ["+v_error_message+"]")
| |
− | return 0
| |
− |
| |
− | """
| |
− | f_get_instances recovers instances objects
| |
− |
| |
− | :return : instances objects
| |
− | """
| |
− | def f_get_instances():
| |
− | v_method = "GET"
| |
− | v_url = "http://my_sqwareweb_url/lib/apiUpdate.php"
| |
− | t_headers = {'Authorization':'Bearer '+v_bearer_token, 'Content-Type': 'application/json'}
| |
− |
| |
− | v_response = f_api_request(v_method, v_url, t_headers=t_headers) # API request
| |
− | v_json_response = json.loads(v_response.text)
| |
− | if "error_message" not in v_json_response:
| |
− | v_instances = v_json_response['results'] # Get instances
| |
− | print(v_instances)
| |
− | return 1
| |
− | else:
| |
− | v_error_message = v_json_response['error_message']
| |
− | print("Error message ["+v_error_message+"]")
| |
− | return 0
| |
− |
| |
− | """
| |
− | f_post_instance create new instance object
| |
− |
| |
− | :param t_data : JSON object data
| |
− | :return : request response
| |
− | """
| |
− | def f_post_instance(t_data):
| |
− | v_method = "POST"
| |
− | v_url = "http://my_sqwareweb_url/lib/apiUpdate.php"
| |
− | t_headers = {'Authorization':'Bearer '+v_bearer_token, 'Content-Type': 'application/json'}
| |
− | t_data = json.dumps(t_data)
| |
− |
| |
− | v_response = f_api_request(v_method, v_url, t_headers=t_headers, t_data=t_data) # API request
| |
− | v_json_response = json.loads(v_response.text)
| |
− | if "error_message" not in v_json_response:
| |
− | print("Insert with success !")
| |
− | return 1
| |
− | else:
| |
− | v_error_message = v_json_response['error_message']
| |
− | print("Error message ["+v_error_message+"]")
| |
− | return 0
| |
− |
| |
− | """
| |
− | f_put_instance update instance object
| |
− |
| |
− | :param v_dbalias : dbalias name
| |
− | :param t_data : JSON object data
| |
− | :return : request response
| |
− | """
| |
− | def f_put_instance(v_dbalias, t_data):
| |
− | v_method = "PUT"
| |
− | v_url = "http://my_sqwareweb_url/lib/apiUpdate.php?dbalias="+v_dbalias
| |
− | t_headers = {'Authorization':'Bearer '+v_bearer_token, 'Content-Type': 'application/json'}
| |
− | t_data = json.dumps(t_data)
| |
− |
| |
− | v_response = f_api_request(v_method, v_url, t_headers=t_headers, t_data=t_data) # API request
| |
− | v_json_response = json.loads(v_response.text)
| |
− | if "error_message" not in v_json_response:
| |
− | print("Update with success !")
| |
− | return 1
| |
− | else:
| |
− | v_error_message = v_json_response['error_message']
| |
− | print("Error message ["+v_error_message+"]")
| |
− | return 0
| |
− |
| |
− | def main():
| |
− | # Variables
| |
− | v_username = "toto"
| |
− | v_password = "toto"
| |
− | v_dbalias = "toto"
| |
− |
| |
− | # Get bearer token
| |
− | f_get_bearer_token(v_username, v_password)
| |
− |
| |
− | # Post new instance
| |
− | t_data = {
| |
− | "dbalias" :v_dbalias,
| |
− | "rdbmsname" :"cassandra",
| |
− | "virt_host_name":"AA-TEST-API",
| |
− | "host_name" :"NPW",
| |
− | "username" :"system",
| |
− | "port" :"1430",
| |
− | "comments" :"desc IPS_A",
| |
− | "contact" :"OAY .L",
| |
− | "status" :"ON",
| |
− | "client" :"CUST2",
| |
− | "env" :"PRD3",
| |
− | "globalhost" :"A",
| |
− | "custom1" :"B",
| |
− | "custom2" :"C",
| |
− | "dbaname" :v_username,
| |
− | "comments_upd" :"insert new instance by API"
| |
− | }
| |
− |
| |
− | f_post_instance(t_data)
| |
− |
| |
− | # Get new instance
| |
− | f_get_instance(v_dbalias)
| |
− |
| |
− | # Put new instance
| |
− | t_data = {
| |
− | "rdbmsname" :"mysql",
| |
− | "virt_host_name":"AA-TEST-API",
| |
− | "host_name" :"NPW",
| |
− | "username" :"system",
| |
− | "port" :"1430",
| |
− | "comments" :"desc IPS_A",
| |
− | "contact" :"OAY .L",
| |
− | "status" :"OFF",
| |
− | "client" :"CUST2",
| |
− | "env" :"PRD3",
| |
− | "globalhost" :"A",
| |
− | "custom1" :"B",
| |
− | "custom2" :"C",
| |
− | "comments_upd" : "update instance status by API"
| |
− | }
| |
− |
| |
− | f_put_instance(v_dbalias, t_data)
| |
− |
| |
− | # Get all instances
| |
− | f_get_instances()
| |
− |
| |
− | if __name__ == '__main__':
| |
− | main()
| |
− | | |
− | ===PHP===
| |
− | <?php
| |
− |
| |
− | $v_bearer_token = "";
| |
− |
| |
− | /**
| |
− | * f_api_request does API request
| |
− | *
| |
− | * @param String $v_method : request method
| |
− | * @param String $v_url : website url
| |
− | * @param Array $t_headers : JSON object headers
| |
− | * @param Array $t_data : JSON object data
| |
− | * @return $v_response : API request return
| |
− | */
| |
− | function f_api_request($v_method, $v_url, $t_headers=[], $t_data='{}'){
| |
− | $v_curl = curl_init();
| |
− |
| |
− | curl_setopt_array($v_curl, array(
| |
− | CURLOPT_URL => $v_url,
| |
− | CURLOPT_RETURNTRANSFER => true,
| |
− | CURLOPT_ENCODING => '',
| |
− | CURLOPT_MAXREDIRS => 10,
| |
− | CURLOPT_TIMEOUT => 0,
| |
− | CURLOPT_FOLLOWLOCATION => true,
| |
− | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
| |
− | CURLOPT_CUSTOMREQUEST => $v_method,
| |
− | CURLOPT_POSTFIELDS => $t_data,
| |
− | CURLOPT_HTTPHEADER => $t_headers,
| |
− | ));
| |
− |
| |
− | $v_response = curl_exec($v_curl);
| |
− | return $v_response;
| |
− | }
| |
− |
| |
− | /**
| |
− | * f_get_bearer_token recovers bearer token
| |
− | *
| |
− | * @param String $v_username : account username
| |
− | * @param String $v_password : account password
| |
− | * @return $v_bearer_token : bearer token
| |
− | */
| |
− | function f_get_bearer_token($v_username, $v_password){
| |
− | $v_method = "POST";
| |
− | $v_url = "http://my_sqwareweb_url/lib/apiUpdate_login.php";
| |
− | $t_headers = array('Content-Type: application/json');
| |
− | $t_data = json_encode(array("username" => $v_username, "password" => $v_password), JSON_FORCE_OBJECT); // Crendentials for connection
| |
− |
| |
− | $v_response = f_api_request($v_method, $v_url, $t_headers=$t_headers, $t_data=$t_data); // API request
| |
− | $v_json_response = json_decode($v_response, true);
| |
− | if(!array_key_exists("error_message", $v_json_response)){
| |
− | global $v_bearer_token;
| |
− | $v_bearer_token = $v_json_response['results'][0]['token']; // Get token response
| |
− | echo("Bearer token : $v_bearer_token");
| |
− | return 0;
| |
− | }
| |
− | else{
| |
− | $v_error_message = $v_json_response['error_message'];
| |
− | echo("Error message [$v_error_message]");
| |
− | return 1;
| |
− | }
| |
− | }
| |
− |
| |
− | /**
| |
− | * f_get_instance recovers instance object
| |
− | *
| |
− | * @param String $v_dbalias : dbalias name
| |
− | * @return $v_instance : instance object
| |
− | */
| |
− | function f_get_instance($v_dbalias){
| |
− | global $v_bearer_token;
| |
− | $v_method = "GET";
| |
− | $v_url = "http://my_sqwareweb_url/lib/apiUpdate.php?dbalias=".$v_dbalias;
| |
− | $t_headers = array('Authorization: Bearer '.$v_bearer_token.'', 'Content-Type: application/json');
| |
− |
| |
− | $v_response = f_api_request($v_method, $v_url, $t_headers=$t_headers); // API request
| |
− | $v_json_response = json_decode($v_response, true);
| |
− | if(!array_key_exists("error_message", $v_json_response)){
| |
− | $v_instance = $v_json_response['results'][0]; // Get instance
| |
− | var_dump($v_instance);
| |
− | return 0;
| |
− | }
| |
− | else{
| |
− | $v_error_message = $v_json_response['error_message'];
| |
− | echo("Error message [$v_error_message]");
| |
− | return 1;
| |
− | }
| |
− | }
| |
− |
| |
− | /**
| |
− | * f_get_instances recovers instances objects
| |
− | *
| |
− | * @return $v_instances : instances objects
| |
− | */
| |
− | function f_get_instances(){
| |
− | global $v_bearer_token;
| |
− | $v_method = "GET";
| |
− | $v_url = "http://my_sqwareweb_url/lib/apiUpdate.php";
| |
− | $t_headers = array('Authorization: Bearer '.$v_bearer_token.'', 'Content-Type: application/json');
| |
− |
| |
− | $v_response = f_api_request($v_method, $v_url, $t_headers=$t_headers); # API request
| |
− | $v_json_response = json_decode($v_response, true);
| |
− | if(!array_key_exists("error_message", $v_json_response)){
| |
− | $v_instance = $v_json_response['results']; // Get instances
| |
− | var_dump($v_instance);
| |
− | return 0;
| |
− | }
| |
− | else{
| |
− | $v_error_message = $v_json_response['error_message'];
| |
− | echo("Error message [$v_error_message]");
| |
− | return 1;
| |
− | }
| |
− | }
| |
− |
| |
− | /**
| |
− | * f_post_instance create new instance object
| |
− | *
| |
− | * @param Array $t_data : JSON object data
| |
− | * @return Array mixed[] : request response
| |
− | */
| |
− | function f_post_instance($t_data){
| |
− | global $v_bearer_token;
| |
− | $v_method = "POST";
| |
− | $v_url = "http://my_sqwareweb_url/lib/apiUpdate.php";
| |
− | $t_headers = array('Authorization: Bearer '.$v_bearer_token.'', 'Content-Type: application/json');
| |
− | $t_data = json_encode($t_data, JSON_FORCE_OBJECT);
| |
− |
| |
− | $v_response = f_api_request($v_method, $v_url, $t_headers=$t_headers, $t_data=$t_data); // API request
| |
− | $v_json_response = json_decode($v_response, true);
| |
− | if(!array_key_exists("error_message", $v_json_response)){
| |
− | echo("Insert with success !");
| |
− | return 0;
| |
− | }
| |
− | else{
| |
− | $v_error_message = $v_json_response['error_message'];
| |
− | echo("Error message [$v_error_message]");
| |
− | return 1;
| |
− | }
| |
− | }
| |
− |
| |
− | /**
| |
− | * f_put_instance update instance object
| |
− | *
| |
− | * @param String $v_dbalias : dbalias name
| |
− | * @param Array $t_data : JSON object data
| |
− | * @return Array mixed[] : request response
| |
− | */
| |
− | function f_put_instance($v_dbalias, $t_data){
| |
− | global $v_bearer_token;
| |
− | $v_method = "PUT";
| |
− | $v_url = "http://my_sqwareweb_url/lib/apiUpdate.php?dbalias=".$v_dbalias;
| |
− | $t_headers = array('Authorization: Bearer '.$v_bearer_token.'', 'Content-Type: application/json');
| |
− | $t_data = json_encode($t_data, JSON_FORCE_OBJECT);
| |
− |
| |
− | $v_response = f_api_request($v_method, $v_url, $t_headers=$t_headers, $t_data=$t_data); // API request
| |
− | $v_json_response = json_decode($v_response, true);
| |
− | if(!array_key_exists("error_message", $v_json_response)){
| |
− | echo("Update with success !");
| |
− | return 0;
| |
− | }
| |
− | else{
| |
− | $v_error_message = $v_json_response['error_message'];
| |
− | echo("Error message [$v_error_message]");
| |
− | return 1;
| |
− | }
| |
− | }
| |
− |
| |
− | function main(){
| |
− | // Variables
| |
− | $v_username = "toto";
| |
− | $v_password = "toto";
| |
− | $v_dbalias = "toto";
| |
− |
| |
− | // Get bearer token
| |
− | f_get_bearer_token($v_username, $v_password);
| |
− |
| |
− | // Post new instance
| |
− | $t_data = array(
| |
− | "dbalias" => $v_dbalias,
| |
− | "rdbmsname" => "cassandra",
| |
− | "virt_host_name" => "AA-TEST-API",
| |
− | "host_name" => "NPW",
| |
− | "username" => "system",
| |
− | "port" => "1430",
| |
− | "comments" => "desc IPS_A",
| |
− | "contact" => "OAY .L",
| |
− | "status" => "ON",
| |
− | "client" => "CUST2",
| |
− | "env" => "PRD3",
| |
− | "globalhost" => "A",
| |
− | "custom1" => "B",
| |
− | "custom2" => "C",
| |
− | "dbaname" => $v_username,
| |
− | "comments_upd" => "insert new instance by API"
| |
− | );
| |
− |
| |
− | f_post_instance($t_data);
| |
− |
| |
− | // Get new instance
| |
− | f_get_instance($v_dbalias);
| |
− |
| |
− | // Put new instance
| |
− | $t_data = array(
| |
− | "dbalias" => $v_dbalias,
| |
− | "rdbmsname" => "mysql",
| |
− | "virt_host_name" => "AA-TEST-API",
| |
− | "host_name" => "NPW",
| |
− | "username" => "system",
| |
− | "port" => "1430",
| |
− | "comments" => "desc IPS_A",
| |
− | "contact" => "OAY .L",
| |
− | "status" => "OFF",
| |
− | "client" => "CUST2",
| |
− | "env" => "PRD3",
| |
− | "globalhost" => "A",
| |
− | "custom1" => "B",
| |
− | "custom2" => "C",
| |
− | "comments_upd" => "update instance status by API"
| |
− | );
| |
− |
| |
− | f_put_instance($v_dbalias, $t_data);
| |
− |
| |
− | // Get all instances
| |
− | f_get_instances();
| |
− | }
| |
− |
| |
− | main();
| |
− |
| |
− | ?>
| |
− | | |
− | ===Shell===
| |
− | #!/bin/sh
| |
− |
| |
− | v_bearer_token=""
| |
− | v_tempfile=api_dbSQWare.tmp
| |
− |
| |
− | <<COMMENTS
| |
− | f_get_bearer_token recovers bearer token
| |
− |
| |
− | :param v_username : account username
| |
− | :param v_password : account password
| |
− | :param v_tempfile : temporary file
| |
− | :return : bearer token
| |
− | COMMENTS
| |
− | f_get_bearer_token(){
| |
− | v_username="$1"
| |
− | v_password="$2"
| |
− | v_tempfile="$3"
| |
− |
| |
− | curl --location --request POST "http://my_sqwareweb_url/lib/apiUpdate_login.php" -H "Content-Type:application/json" -d '{"username":"'$v_username'","password":"'$v_password'"}' > $v_tempfile 2>$v_tempfile.err
| |
− | if [ $(grep -c '"error_message"' $v_tempfile) -eq 0 ]
| |
− | then
| |
− | # Get bearer token
| |
− | v_bearer_token=`cat $v_tempfile|grep '\"token\":\"' | cut -d'"' -f4`
| |
− | echo "Bearer token : $v_bearer_token"
| |
− | return 0
| |
− | else
| |
− | v_error_message=`cat $v_tempfile|grep '\"error_message\": \"' | cut -d'"' -f4`
| |
− | echo "Error message [$v_error_message]"
| |
− | return 1
| |
− | fi
| |
− | }
| |
− |
| |
− | <<COMMENTS
| |
− | f_get_instance recovers instance object
| |
− |
| |
− | :param v_dbalias : dbalias name
| |
− | :return : instance object
| |
− | COMMENTS
| |
− | f_get_instance(){
| |
− | v_dbalias="$1"
| |
− |
| |
− | curl --location --request GET "http://my_sqwareweb_url/lib/apiUpdate.php?dbalias=$v_dbalias" -H "Authorization: Bearer $v_bearer_token" -H "Content-Type:application/json" > $v_tempfile 2>$v_tempfile.err
| |
− | if [ $(grep -c '"error_message"' $v_tempfile) -eq 0 ]
| |
− | then
| |
− | # Get instance
| |
− | v_instance=`cat $v_tempfile|grep -A 1 '\"results\":'`
| |
− | echo "Instance : $v_instance"
| |
− | return 0
| |
− | else
| |
− | v_error_message=`cat $v_tempfile|grep '\"error_message\": \"' | cut -d'"' -f4`
| |
− | echo "Error message [$v_error_message]"
| |
− | return 1
| |
− | fi
| |
− | }
| |
− |
| |
− | <<COMMENTS
| |
− | f_get_instances recovers instances objects
| |
− |
| |
− | :return : instances objects
| |
− | COMMENTS
| |
− | f_get_instances(){
| |
− | curl --location --request GET "http://my_sqwareweb_url/lib/apiUpdate.php" -H "Authorization: Bearer $v_bearer_token" -H "Content-Type:application/json" > $v_tempfile 2>$v_tempfile.err
| |
− | if [ $(grep -c '"error_message"' $v_tempfile) -eq 0 ]
| |
− | then
| |
− | # Get instances
| |
− | v_instances=`cat $v_tempfile|grep -A 1 '\"results\":'`
| |
− | echo "Instances : $v_instances"
| |
− | return 0
| |
− | else
| |
− | v_error_message=`cat $v_tempfile|grep '\"error_message\": \"' | cut -d'"' -f4`
| |
− | echo "Error message [$v_error_message]"
| |
− | return 1
| |
− | fi
| |
− | }
| |
− |
| |
− | <<COMMENTS
| |
− | f_post_instance create new instance object
| |
− |
| |
− | :param t_data : JSON object data
| |
− | :return : request response
| |
− | COMMENTS
| |
− | f_post_instance(){
| |
− | t_data="$1"
| |
− |
| |
− | curl --location --request POST "http://my_sqwareweb_url/lib/apiUpdate.php" -H "Authorization: Bearer $v_bearer_token" -H "Content-Type:application/json" -d "$t_data" > $v_tempfile 2>$v_tempfile.err
| |
− | if [ $(grep -c '"error_message"' $v_tempfile) -eq 0 ]
| |
− | then
| |
− | echo "Insert with success !"
| |
− | return 0
| |
− | else
| |
− | v_error_message=`cat $v_tempfile|grep '\"error_message\": \"' | cut -d'"' -f4`
| |
− | echo "Error message [$v_error_message]"
| |
− | return 1
| |
− | fi
| |
− | }
| |
− |
| |
− | <<COMMENTS
| |
− | f_put_instance update instance object
| |
− |
| |
− | :param v_dbalias : dbalias name
| |
− | :param t_data : JSON object data
| |
− | :return : request response
| |
− | COMMENTS
| |
− | f_put_instance(){
| |
− | v_dbalias="$1"
| |
− | t_data="$2"
| |
− |
| |
− | echo $t_data > test.tmp
| |
− | curl --location --request PUT "http://my_sqwareweb_url/lib/apiUpdate.php?dbalias=$v_dbalias" -H "Authorization: Bearer $v_bearer_token" -H "Content-Type:application/json" -d "$t_data" > $v_tempfile 2>$v_tempfile.err
| |
− | if [ $(grep -c '"error_message"' $v_tempfile) -eq 0 ]
| |
− | then
| |
− | echo "Update with success !"
| |
− | return 0
| |
− | else
| |
− | v_error_message=`cat $v_tempfile|grep '\"error_message\": \"' | cut -d'"' -f4`
| |
− | echo "Error message [$v_error_message]"
| |
− | return 1
| |
− | fi
| |
− | }
| |
− |
| |
− | main(){
| |
− | # Variables
| |
− | v_username="toto";
| |
− | v_password="toto";
| |
− | v_dbalias="toto";
| |
− |
| |
− | # Get bearer token
| |
− | f_get_bearer_token $v_username $v_password $v_tempfile
| |
− |
| |
− | # Post new instance
| |
− | t_data='{"dbalias":"'$v_dbalias'","rdbmsname":"cassandra","virt_host_name":"AA-TEST-API","host_name":"NPW","username":"system","port":"1430","comments":"desc IPS_A","contact":"OAY .L","status":"ON","client":"CUST2","env":"PRD3","globalhost":"A","custom1":"B","custom2":"C","dbaname":"'$v_username'","comments_upd":"insert new instance by API"}'
| |
− | f_post_instance "$t_data"
| |
− |
| |
− | # Get new instance
| |
− | f_get_instance $v_dbalias
| |
− |
| |
− | # Put new instance
| |
− | t_data='{"rdbmsname":"mysql","virt_host_name":"AA-TEST-API","host_name":"NPW","username":"system","port":"1430","comments":"desc IPS_A","contact":"OAY .L","status":"OFF","client":"CUST2","env":"PRD3","globalhost":"A","custom1":"B","custom2":"C","comments_upd":"update instance status by API"}'
| |
− | f_put_instance $v_dbalias "$t_data"
| |
− |
| |
− | # Get all instances
| |
− | f_get_instances
| |
− | }
| |
− |
| |
− | main
| |