Checkmk local script issu

Please avoid previous script take below as the updated script.
I have tried to run a bash script in a host which is added in the checkmk
.
path of the script : /usr/lib/check_mk_agent/local

and the script is

!/bin/bash

host=hostname -I

result1=$(mysql -u root -N<<<“SELECT MEMBER_STATE FROM performance_schema.replication_group_members where MEMBER_HOST=’$host’;”)

#result=echo $result1 | sed 's/ *$//g'
if [[ “$result1” == “ONLINE” ]];
then
result=“ONLINE”
else
result=$result1
fi

if [[ “$result” == “ONLINE” ]];
then
status=0
statustxt=“Replication status - OK”
#echo “OK”

elif [[ “$result” == “RECOVERY” ]];
then
status=1
statustxt=“Replication status - WARNING”

else
status=2
statustxt=“Replication status - CRITICAL”
echo “From Critical Condition”
fi

echo “$status GROUP_REPLICATION - $statustxt”

Above is the script and output its giving 0 status but in checkmk its showing as critical status .
Please avoid early post . Please run this script and check an et me know any further changes to be done. When i am running the script i am getting 0 status but in checkmk its showing critical. Here i am just taking the member_state (online,offline,warning) of a server from a table in mysql and updating the status in the checkmk and its written in /usr/lib/check_mk_agent/local.

Please help me why the status ot reflecting properly n checkmk , its showing critical only

For me your script fails with

x.sh: line 16: syntax error near unexpected token `then'
x.sh: line 16: `then'

Also, the variable $result1 is never used and $result is never set.
I’d say there is no way the script you posted is giving status 0. It simply doesn’t run.

1 Like

Hi,
nice exercise :slight_smile:
I don’t know if the line with the command for result1 is correct - the rest should look like these:

#!/bin/bash

host=$(hostname -I)

result1=$(mysql -u root -N<<<"SELECT MEMBER_STATE FROM performance_schema.replication_group_members where MEMBER_HOST='$host';")

result=$(echo $result1 | sed 's/ *$//g')
if [ "$result" = "ONLINE" ]
then
status=0
statustxt="Replication status - OK"
#echo "OK"
elif [ "$result" = "RECOVERY" ]
then
status=1
statustxt="Replication status - WARNING"
else
status=2
statustxt="Replication status - CRITICAL"
# echo "From Critical Condition"
fi

echo "$status GROUP_REPLICATION - $statustxt"

Karl

1 Like

Almost :wink:

The line result=echo $result1 | sed 's/ *$//g' needs either backticks or $(…). In the original post it had backticks, what’s why it rendered as literal text.

The CRIT case won’t work because of the echo "…" line. It will upset checkmk to find a line that doesn’t look like 0 name - text.

Hi @Dirk,
thanks - now I’ve found all errors :slight_smile:

Karl

root@uat: /usr/lib/check_mk_agent/local# bash replication_status
0 GROUP_REPLICATION - Replication status - OK

I am getting the output as this

but in checkmk its showing critical only
Can you please let me know why is it so.
and one does this self written check need to be kept in local or inside plugin since in local after sometime this local checkmk service is moving to vanished service and mentioning status as “UNKNOWN”

this line

result1=$(mysql -u root -N<<<“SELECT MEMBER_STATE FROM performance_schema.replication_group_members where MEMBER_HOST=’$host’;”)

is giving correct value as “online” without column name
and i am getting the output while running this bash file as

0 GROUP_REPLICATION - Replication status - OK

but in checkmk its showing critical
cna you please help me where i am lagging . any further changes to be done. And this check i have done in local . So after few hours in checkmk its moving dis service as unknown and vanised service. So where i need to move this self written check so that it wont move to vanished service.

What does

check_mk_agent | sed -n '/^<<<local>>>/,/^<<</p;'

print? (This command will show the section <<<local>>> of the agent output.)

Hello ,

out for check_mk_agent | sed -n ‘/^<<>>/,/^<<</p;’

<<>>
0 GROUP_REPLICATION - Replication status - OK
<<<mysql_ping>>>

Hello ,

out for check_mk_agent | sed -n ‘/^<<>>/,/^<<</p;’

<<>>
0 GROUP_REPLICATION - Replication status - OK
<<<mysql_ping>>>

Its not resolved
Please let me know if we keep our customised script under check_mk_agent/plugins/ why its not getting reflected in the checkmk server with the output

Hello,
you have to put your local check into the directory /usr/lib/check_mk_agent/local.

Karl

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.