From 16e8c440214e9b3bff98140e594f34cd72169671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Vysko=C4=8Dil?= <vyskocilpavel@muni.cz> Date: Mon, 17 Feb 2020 19:09:47 +0100 Subject: [PATCH] Added rpc_status.sh * Added script for check if Perun RPC is available --- README.md | 26 ++++++++++++++++++++++++++ rpc_status.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 rpc_status.sh diff --git a/README.md b/README.md index c643b01..c075345 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,32 @@ This script checks if the LDAP servers are accessible hostnames="" </pre> +### rpc_status.sh +This script checks if the RPC server is accessible and if RPC returns valid user + +* Requirements: + * library *bc* + <pre> + apt-get install bc + </pre> +* Attributes to be filled: + <pre> + # RPC username + USER="" + + # RPC password + PASSWORD="" + + # RPC domain with authentication method + # Example: "perun.cesnet.cz/krb" + DOMAIN="" + + # Valid userId - This id will be used in getUserById call + USER_ID="" + </pre> + + + ## List of plugins Plugins are located in /usr/lib/check_mk/plugins/ diff --git a/rpc_status.sh b/rpc_status.sh new file mode 100644 index 0000000..6f1a851 --- /dev/null +++ b/rpc_status.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# RPC username +USER="" + +# RPC password +PASSWORD="" + +# RPC domain with authentication method +# Example: "perun.cesnet.cz/krb" +DOMAIN="" + +# Valid userId - This id will be used in getUserById call +USER_ID="" + +URL="https://${DOMAIN}/rpc/json/usersManager/getUserById?id=${USER_ID}" + +START_TIME=$(date +%s%N) +RPC_RESULT=$(timeout 10 curl --user ${USER}:${PASSWORD} ${URL} 2>&1) +END_TIME=$(date +%s%N) +TOTAL_TIME=$(echo "scale=4;$(expr ${END_TIME} - ${START_TIME}) / 1000000000" | bc -l) +if [[ $RPC_RESULT == *\"id\":${USER_ID}* ]]; then + echo "0 rpc_status total_time=${TOTAL_TIME} OK" +else + echo "2 rpc_status total_time=${TOTAL_TIME} ${RPC_RESULT}" +fi -- GitLab