Expand my Community achievements bar.

SOLVED

curl command to check system console up or not?

Avatar

Level 3

Hi,

I am running below curl function status check from jump servers to verify whether system console is up and running or not across many publishers. We have almost 50+ publishers running across different environments (Prod/Dev/DTQ/SIT etc..).

Problem here is all environments doesn't have common 499 bundles active. Some publishers have 500 active and some have 497 active bundles and some other servers varies with count. 

 

I am looking for a curl command that checks and confirms system console is up and running and also 

all active bundles in total are running. Can someone please assist?

 

function status()
{
/bin/su - root -c "curl -u 'admin':'admin' http://localhost:41000/system/console/bundles/.json | cut -d':' -f2,3 | egrep 499 >> /dev/null"
EXIT_STATUS=`echo $?`
if [ $EXIT_STATUS != 0 ]
then
echo ""
echo "Service is not running"
else
echo ""
echo "Service is running"
fi
}

 

 

Sample Output of below curl

----------------------------

curl -u 'admin':'admin' http://localhost:41000/system/console/bundles/.json | cut -d':' -f2,3

 

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 93826 0 93826 0 0 3847k 0 --:--:-- --:--:-- --:--:-- 4363k
"Bundle information: 497 bundles in total - all 497 bundles active.","s"

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hello @surendarm613658 

Here, I wrote a script that does what you want. It relies on jq to parse the JSON response (you can play around with jq to learn its syntax and experiment for free by going here). It will need some adapting to iterate through your 50+ instances of course 

instance="http://localhost:4502"
echo "Checking bundle status for instance at ${instance}"

# Store response JSON
response=$(curl -u "admin:admin" "${instance}/system/console/bundles/.json")
echo $(jq -r '.status' <<< ${response})

# The s property holds 5 items:
# 1. the total number or bundles
# 2. The number of active bundles
# 3. The number of active fragments
# 4. The number of resolved bundles
# 5. The number of installed bundles
# So to check if our bundles are active, we just need to make sure indexes 3 and 4 hold 0
bundles_active=$(jq -r 'if (.s[3] == 0 and .s[4] == 0) then true else false end' <<< ${response})
echo $bundles_active

if $bundles_active; then 
    echo "All bundles active"
else
    # If there is an issue, print the total number of inactive bundles
    inactive_bundles=$(jq -r '.s[2] + .s[3]' <<< ${response})
    echo "Warning, instance ${instance} has ${inactive_bundles} bundles inactive"
fi

Here is the output for the following instance, which is not OK as it has 2 installed but inactive bundles:

theop76211228_0-1589476832509.png

$ ./bundle_status.sh 

Checking bundle status for instance at http://localhost:4502
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  130k    0  130k    0     0  6209k      0 --:--:-- --:--:-- --:--:-- 6209k
Bundle information: 705 bundles in total, 699 bundles active, 4 bundles active fragments, 2 bundles installed.
false
Warning, instance http://localhost:4502 has 2 bundles inactive

 

 

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Hello @surendarm613658 

Here, I wrote a script that does what you want. It relies on jq to parse the JSON response (you can play around with jq to learn its syntax and experiment for free by going here). It will need some adapting to iterate through your 50+ instances of course 

instance="http://localhost:4502"
echo "Checking bundle status for instance at ${instance}"

# Store response JSON
response=$(curl -u "admin:admin" "${instance}/system/console/bundles/.json")
echo $(jq -r '.status' <<< ${response})

# The s property holds 5 items:
# 1. the total number or bundles
# 2. The number of active bundles
# 3. The number of active fragments
# 4. The number of resolved bundles
# 5. The number of installed bundles
# So to check if our bundles are active, we just need to make sure indexes 3 and 4 hold 0
bundles_active=$(jq -r 'if (.s[3] == 0 and .s[4] == 0) then true else false end' <<< ${response})
echo $bundles_active

if $bundles_active; then 
    echo "All bundles active"
else
    # If there is an issue, print the total number of inactive bundles
    inactive_bundles=$(jq -r '.s[2] + .s[3]' <<< ${response})
    echo "Warning, instance ${instance} has ${inactive_bundles} bundles inactive"
fi

Here is the output for the following instance, which is not OK as it has 2 installed but inactive bundles:

theop76211228_0-1589476832509.png

$ ./bundle_status.sh 

Checking bundle status for instance at http://localhost:4502
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  130k    0  130k    0     0  6209k      0 --:--:-- --:--:-- --:--:-- 6209k
Bundle information: 705 bundles in total, 699 bundles active, 4 bundles active fragments, 2 bundles installed.
false
Warning, instance http://localhost:4502 has 2 bundles inactive

 

 

Avatar

Level 3
Hi - Thanks a lot for your efforts. It worked perfectly. Much appreciated!