Skip to main content

Hello,

I am currently working on the automatic creation of Business Activities, respecting specific groupings to display these Business Activities on maps and provide an application-specific view suitable for sharing or displaying on screens for all critical applications.

To achieve this, I use CLAPI to automatically create Business Activities, specifying only the server type (e.g., DB, APP, RDS, etc.).

I now also have access to the Map API and have added functionality to my script for automatically creating views tailored to my applications and Business Activities, based on a file provided to the script.

However, I am currently stuck when trying to add Business Activities to the map using the Map API. I am attempting to create a map and add a Business Activity (BA) to it using its ID from an external script, but I consistently encounter an issue where the BA is reported as not found.

Below are the errors and scripts:

Terminal Output:

[root@srvu3016 ~]# ./test.sh 
Authenticating with Centreon Map API...
Authentication successful. JWT token obtained.
Creating a new map named 'BA_Map_1732182662'...
Create Map Response:
{
  "id": 180,
  "name": "BA_Map_1732182662",
  "locked": false,
  "hidden": false,
  "viewId": 206
}
Map 'BA_Map_1732182662' created successfully. mapId: 180, viewId: 206.
Map view validated. Response:
{
  "id": 206,
  "latitude": 0.0,
  "longitude": 0.0,
  "perspective": {
    "zoomperspective": 1.0,
    "xperspective": 0.0,
    "yperspective": 0.0
  },
  "scale": 1.0,
  "resources": ],
  "widgets": <],
  "shapes": ]],
  "media": ],
  "links": 🙂,
  "containers": ,],
  "empty": false,
  "geo": false,
  "status": "NA",
  "dx": 0.0,
  "dy": 0.0
}
Adding Business Activity (ID: 463) to the map...
Resource Data Sent:
{
  "resources": :
    {
      "type": "BUSINESS_ACTIVITY",
      "resourceId": 463,
      "useResourceName": true,
      "graphics": {
        "borderColor": "#000000",
        "displayImage": true,
        "displayLabel": true,
        "fillColor": "#0077b6",
        "fontColor": "#ffffff",
        "fontFamily": "Open Sans",
        "fontSize": 14,
        "fontStyle": 1,
        "height": 100,
        "horizontalAlign": "LEFT",
        "horizontalLabelPosition": "TOP",
        "label": "Example BA",
        "layer": 0,
        "line": "SOLID",
        "locked": false,
        "opaque": true,
        "opacity": 100,
        "style": "ICON",
        "thickness": 2,
        "useBackgroundStatusColor": true,
        "useFontStatusColor": true,
        "verticalAlign": "TOP",
        "verticalLabelPosition": "TOP",
        "width": 200,
        "x": 100,
        "y": 100
      }
    }
  ]
}
Add Resource Response:
{
  "timestamp": "2024-11-21T09:51:03.099+00:00",
  "status": 404,
  "error": "Not Found",
  "path": "/centreon-map/api/beta/maps/180/views/206/resources"
}
Failed to add Business Activity to the map.
API response:
{
  "timestamp": "2024-11-21T09:51:03.099+00:00",
  "status": 404,
  "error": "Not Found",
  "path": "/centreon-map/api/beta/maps/180/views/206/resources"
}

 

Bash Script:

 

#!/bin/bash

 

# Connection parameters

serverURL=

 

# Prompt for username and password securely

username=

password=

 

# Authenticate and obtain JWT token

echo "Authenticating with Centreon Map API..."

auth_response=$(curl -k -s -X POST "$serverURL/centreon-map/api/beta/auth/sign-in" \

  -H "Content-Type: application/json" \

  -H "X-Client-Version: 24.10.0" \

  -d "{\"login\":\"$username\",\"password\":\"$password\"}")

 

jwtToken=$(echo "$auth_response" | jq -r '.jwtToken')

 

if s -z "$jwtToken" ] || > "$jwtToken" == "null" ]; then

  echo "Authentication failed. Response:"

  echo "$auth_response" | jq .

  exit 1

fi

echo "Authentication successful. JWT token obtained."

 

# Create a new map

map_name="BA_Map_$(date +%s)"

echo "Creating a new map named '$map_name'..."

create_map_response=$(curl -k -s -X POST "$serverURL/centreon-map/api/beta/maps" \

  -H "Content-Type: application/json" \

  -H "Authorization: Bearer $jwtToken" \

  -d "{\"name\":\"$map_name\"}")

 

echo "Create Map Response:"

echo "$create_map_response" | jq .

 

mapId=$(echo "$create_map_response" | jq -r '.id')

viewId=$(echo "$create_map_response" | jq -r '.viewId')

 

if > -z "$mapId" ] || r -z "$viewId" ] || < "$mapId" == "null" ] || $ "$viewId" == "null" ]; then

  echo "Failed to create the map. Response:"

  echo "$create_map_response" | jq .

  exit 1

fi

echo "Map '$map_name' created successfully. mapId: $mapId, viewId: $viewId."

 

# Validate map and view existence

validate_view_response=$(curl -k -s -X GET "$serverURL/centreon-map/api/beta/maps/$mapId/views/$viewId" \

  -H "Authorization: Bearer $jwtToken")

 

if echo "$validate_view_response" | grep -q '"id"'; then

  echo "Map view validated. Response:"

  echo "$validate_view_response" | jq .

else

  echo "Failed to validate the map view. Response:"

  echo "$validate_view_response" | jq .

  exit 1

fi

 

# Define BA details

ba_id=463  # Replace with the actual Business Activity ID

ba_name="Example BA"

 

# Add BA to the map as a resource

echo "Adding Business Activity (ID: $ba_id) to the map..."

resource_data=$(cat <<EOF

{

  "resources": e

    {

      "type": "BUSINESS_ACTIVITY",

      "resourceId": $ba_id,

      "useResourceName": true,

      "graphics": {

        "borderColor": "#000000",

        "displayImage": true,

        "displayLabel": true,

        "fillColor": "#0077b6",

        "fontColor": "#ffffff",

        "fontFamily": "Open Sans",

        "fontSize": 14,

        "fontStyle": 1,

        "height": 100,

        "horizontalAlign": "LEFT",

        "horizontalLabelPosition": "TOP",

        "label": "$ba_name",

        "layer": 0,

        "line": "SOLID",

        "locked": false,

        "opaque": true,

        "opacity": 100,

        "style": "ICON",

        "thickness": 2,

        "useBackgroundStatusColor": true,

        "useFontStatusColor": true,

        "verticalAlign": "TOP",

        "verticalLabelPosition": "TOP",

        "width": 200,

        "x": 100,

        "y": 100

      }

    }

  ]

}

EOF

)

 

echo "Resource Data Sent:"

echo "$resource_data" | jq .

 

# Utilisation de l'URL correcte avec /resources et vérification de la méthode HTTP

add_resource_response=$(curl -k -s -X PUT "$serverURL/centreon-map/api/beta/maps/$mapId/views/$viewId/resources" \

  -H "Content-Type: application/json" \

  -H "Authorization: Bearer $jwtToken" \

  -d "$resource_data")

 

echo "Add Resource Response:"

echo "$add_resource_response" | jq .

 

if echo "$add_resource_response" | grep -q '"id"'; then

  echo "Business Activity (ID: $ba_id) successfully added to the map."

else

  echo "Failed to add Business Activity to the map."

  echo "API response:"

  echo "$add_resource_response" | jq .

  exit 1

fi

 

BA Data Example:
453;APP-ESSENCE-AX-APAC-DATABASE;;2;90;80;0
454;APP-ESSENCE-AX-APAC;;2;90;80;0
455;APP-ESSENCE-AX-AMER-AOS-APPLI;;2;90;80;0
456;APP-ESSENCE-AX;;2;80;70;
457;APP-BIZTALK-WW-WW-OS-SRVW9030;;2;90;80;0
458;APP-BIZTALK-WW-WW-VIP-SRVW9030;;2;90;80;0
459;APP-BIZTALK-WW-WW-SERVER-APPLI-SRVW9030;;2;90;80;0
460;APP-BIZTALK-WW-WW-OS-SRVW9031;;2;90;80;0
461;APP-BIZTALK-WW-WW-VIP-SRVW9031;;2;90;80;0
462;APP-BIZTALK-WW-WW-SERVER-APPLI-SRVW9031;;2;90;80;0
463;APP-BIZTALK-WW-WW-OS-SRVW9032;;2;90;80;0
464;APP-BIZTALK-WW-WW-VIP-SRVW9032;;2;90;80;0
465;APP-BIZTALK-WW-WW-SERVER-APPLI-SRVW9032;;2;90;80;0
466;APP-BIZTALK-WW-WW-AOS-APPLI;;2;90;80;0
467;APP-BIZTALK-WW-WW-DB-SRVW9033;;2;90;80;0
468;APP-BIZTALK-WW-WW-OS-SRVW9033;;2;90;80;0
469;APP-BIZTALK-WW-WW-VIP-SRVW9033;;2;90;80;0
470;APP-BIZTALK-WW-WW-SERVER-DATABASE-SRVW9033;;2;90;80;0
471;APP-BIZTALK-WW-WW-DB-SRVW9034;;2;90;80;0
472;APP-BIZTALK-WW-WW-OS-SRVW9034;;2;90;80;0
473;APP-BIZTALK-WW-WW-VIP-SRVW9034;;2;90;80;0

 

I appreciate any advice or guidance on resolving this issue. Thank you!

Antoine SAADA

Be the first to reply!

Reply