Skip to content

Commit 784e866

Browse files
authored
Issue 5 (#6)
* Allow self-signed certificates
1 parent 634cc71 commit 784e866

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

check_rancher2.sh

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
# 20181109 1.0.0 Do not alert for succeeded pods #
3333
# 20190308 1.1.0 Added node(s) check #
3434
# 20190903 1.1.1 Detect invalid hostname (non-API hostname) #
35+
# 20190903 1.2.0 Allow self-signed certificates (-s) #
3536
##########################################################################################
3637
# (Pre-)Define some fixed variables
3738
STATE_OK=0 # define the exit code if status is OK
@@ -40,7 +41,7 @@ STATE_CRITICAL=2 # define the exit code if status is Critical
4041
STATE_UNKNOWN=3 # define the exit code if status is Unknown
4142
export PATH=/usr/local/bin:/usr/bin:/bin:$PATH # Set path
4243
proto=http # Protocol to use, default is http, can be overwritten with -S parameter
43-
version=1.1.1
44+
version=1.2.0
4445

4546
# Check for necessary commands
4647
for cmd in jshon curl [
@@ -60,6 +61,7 @@ Usage: $0 -H Rancher2Address -U user-token -P password [-S] -t checktype [-c clu
6061
\t-U API username (Access Key)\n
6162
\t-P API password (Secret Key)\n
6263
\t-S Use https instead of http\n
64+
\t-s Allow self-signed certificates\n
6365
\t-t Check type (see list below for available check types)\n
6466
\t-c Cluster name (for specific cluster check)\n
6567
\t-p Project name (for specific project check, needed for workload checks)\n
@@ -81,7 +83,7 @@ if [ "${1}" = "--help" -o "${#}" = "0" ];
8183
fi
8284
#########################################################################
8385
# Get user-given variables
84-
while getopts "H:U:P:t:c:p:n:w:o:Sh" Input;
86+
while getopts "H:U:P:t:c:p:n:w:o:Ssh" Input;
8587
do
8688
case ${Input} in
8789
H) apihost=${OPTARG};;
@@ -94,6 +96,7 @@ do
9496
w) workloadname=${OPTARG};;
9597
o) podname=${OPTARG};;
9698
S) proto=https;;
99+
s) selfsigned="-k";;
97100
h) echo -e ${help}; exit ${STATE_UNKNOWN};;
98101
*) echo -e ${help}; exit ${STATE_UNKNOWN};;
99102
esac
@@ -106,7 +109,7 @@ if [ -z $apipass ]; then echo -e "CHECK_RANCHER2 UNKNOWN - Missing API password"
106109
if [ -z $type ]; then echo -e "CHECK_RANCHER2 UNKNOWN - Missing check type"; exit ${STATE_UNKNOWN}; fi
107110
#########################################################################
108111
# Base communication check
109-
apicheck=$(curl -s -o /dev/null -w "%{http_code}" -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project")
112+
apicheck=$(curl -s ${selfsigned} -o /dev/null -w "%{http_code}" -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project")
110113

111114
# Detect failures
112115
if [[ $apicheck = 000 ]]
@@ -126,8 +129,8 @@ case ${type} in
126129

127130
# --- info --- #
128131
info)
129-
api_out_clusters=$(curl -s -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/clusters")
130-
api_out_project=$(curl -s -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project")
132+
api_out_clusters=$(curl -s ${selfsigned} -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/clusters")
133+
api_out_project=$(curl -s ${selfsigned} -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project")
131134
declare -a cluster_ids=( $(echo "$api_out_clusters" | jshon -e data -a -e id) )
132135
declare -a cluster_names=( $(echo "$api_out_clusters" | jshon -e data -a -e name) )
133136
declare -a project_ids=( $(echo "$api_out_project" | jshon -e data -a -e id) )
@@ -162,7 +165,7 @@ cluster)
162165
if [[ -z $clustername ]]; then
163166

164167
# Check status of all clusters
165-
api_out_clusters=$(curl -s -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/clusters")
168+
api_out_clusters=$(curl -s ${selfsigned} -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/clusters")
166169
declare -a cluster_ids=( $(echo "$api_out_clusters" | jshon -e data -a -e id) )
167170
declare -a cluster_names=( $(echo "$api_out_clusters" | jshon -e data -a -e name) )
168171
declare -a healthstatus=( $(echo "$api_out_clusters" | jshon -e data -a -e componentStatuses -a -e conditions -a -e status -u) )
@@ -192,7 +195,7 @@ if [[ -z $clustername ]]; then
192195
else
193196

194197
# Check status of a single cluster
195-
api_out_single_cluster=$(curl -s -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/clusters/${clustername}")
198+
api_out_single_cluster=$(curl -s ${selfsigned} -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/clusters/${clustername}")
196199

197200
# Check if that given cluster name exists
198201
if [[ -n $(echo "$api_out_single_cluster" | grep -i "error") ]]
@@ -228,7 +231,7 @@ node)
228231
if [[ -z $clustername ]]; then
229232

230233
# Check status of all nodes in all clusters
231-
api_out_nodes=$(curl -s -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/nodes")
234+
api_out_nodes=$(curl -s ${selfsigned} -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/nodes")
232235
declare -a node_names=( $(echo "$api_out_nodes" | jshon -e data -a -e nodeName -u) )
233236
declare -a node_status=( $(echo "$api_out_nodes" | jshon -e data -a -e state -u) )
234237
declare -a node_cluster_member=( $(echo "$api_out_nodes" | jshon -e data -a -e clusterId -u) )
@@ -257,7 +260,7 @@ if [[ -z $clustername ]]; then
257260
else
258261

259262
# Check status of all nodes in a specific clusters
260-
api_out_nodes=$(curl -s -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/nodes/?clusterId=${clustername}")
263+
api_out_nodes=$(curl -s ${selfsigned} -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/nodes/?clusterId=${clustername}")
261264

262265
# Check if that given cluster name exists
263266
if [[ -n $(echo "$api_out_nodes" | grep -i "error") ]]
@@ -297,7 +300,7 @@ project)
297300
if [[ -z $projectname ]]; then
298301

299302
# Check status of all projects
300-
api_out_project=$(curl -s -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project")
303+
api_out_project=$(curl -s ${selfsigned} -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project")
301304
declare -a project_ids=( $(echo "$api_out_project" | jshon -e data -a -e id -u) )
302305
declare -a project_names=( $(echo "$api_out_project" | jshon -e data -a -e name -u) )
303306
declare -a cluster_ids=( $(echo "$api_out_project" | jshon -e data -a -e clusterId) )
@@ -327,7 +330,7 @@ if [[ -z $projectname ]]; then
327330
else
328331

329332
# Check status of a single project
330-
api_out_single_project=$(curl -s -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project/${projectname}")
333+
api_out_single_project=$(curl -s ${selfsigned} -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project/${projectname}")
331334

332335
# Check if that given project name exists
333336
if [[ -n $(echo "$api_out_single_project" | grep -i "error") ]]
@@ -357,7 +360,7 @@ if [ -z $projectname ]; then echo -e "CHECK_RANCHER2 UNKNOWN - To check workload
357360
if [[ -z $workloadname ]]; then
358361

359362
# Check status of all workloads within a project (project must be given)
360-
api_out_workloads=$(curl -s -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project/${projectname}/workloads")
363+
api_out_workloads=$(curl -s ${selfsigned} -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project/${projectname}/workloads")
361364

362365
if [[ -n $(echo "$api_out_workloads" | grep -i "ClusterUnavailable") ]]; then
363366
clustername=$(echo ${projectname} | awk -F':' '{print $1}')
@@ -412,7 +415,7 @@ if [[ -z $workloadname ]]; then
412415
else
413416

414417
# Check status of a single workload
415-
api_out_single_workload=$(curl -s -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project/${projectname}/workloads/?name=${workloadname}")
418+
api_out_single_workload=$(curl -s ${selfsigned} -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project/${projectname}/workloads/?name=${workloadname}")
416419

417420
if [[ -n $(echo "$api_out_single_workload" | grep -i "ClusterUnavailable") ]]; then
418421
clustername=$(echo ${projectname} | awk -F':' '{print $1}')
@@ -448,7 +451,7 @@ if [ -z $projectname ]; then echo -e "CHECK_RANCHER2 UNKNOWN - To check pods you
448451
if [[ -z $podname ]]; then
449452

450453
# Check status of all pods within a project (project must be given)
451-
api_out_pods=$(curl -s -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project/${projectname}/pods")
454+
api_out_pods=$(curl -s ${selfsigned} -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project/${projectname}/pods")
452455

453456
if [[ -n $(echo "$api_out_pods" | grep -i "ClusterUnavailable") ]]; then
454457
clustername=$(echo ${projectname} | awk -F':' '{print $1}')
@@ -488,7 +491,7 @@ else
488491
# Check status of a single pod (requires project and namespace)
489492
# Note: This only makes sense when you create static pods!
490493
if [ -z $namespacename ]; then echo -e "CHECK_RANCHER2 UNKNOWN - To check a single pod you must also define the namespace (-n)."; exit ${STATE_UNKNOWN}; fi
491-
api_out_single_pod=$(curl -s -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project/${projectname}/pods/${namespacename}:${podname}")
494+
api_out_single_pod=$(curl -s ${selfsigned} -u "${apiuser}:${apipass}" "${proto}://${apihost}/v3/project/${projectname}/pods/${namespacename}:${podname}")
492495

493496
if [[ -n $(echo "$api_out_single_pod" | grep -i "ClusterUnavailable") ]]; then
494497
clustername=$(echo ${projectname} | awk -F':' '{print $1}')

icinga2/command_check_rancher2.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ object CheckCommand "check_rancher2" {
88
"-U" = "$rancher2_username$"
99
"-P" = "$rancher2_password$"
1010
"-S" = { set_if = "$rancher2_ssl$" }
11+
"-s" = { set_if = "$rancher2_selfsigned_cert$" }
1112
"-t" = "$rancher2_type$"
1213
"-c" = "$rancher2_cluster$"
1314
"-p" = "$rancher2_project$"
@@ -21,4 +22,5 @@ object CheckCommand "check_rancher2" {
2122
#vars.rancher2_username = "token-XXXXX"
2223
#vars.rancher2_password = "iWahca3ohngeiReedeingaiiWahca3ohngeiReedeingai432k1dda"
2324
#vars.rancher2_ssl = true
25+
#vars.rancher2_selfsigned_cert = false
2426
}

0 commit comments

Comments
 (0)