Closed m4rcu5 closed 4 years ago
Hi,
It seems the quotes around $kubectl_command cause kubectl to interpret the whole string as a single command. Leading to the following error.
$kubectl_command
kubectl
$ bash -x /opt/monitoring/plugins/check_kubernetes.sh -K /var/lib/nagios/kube_config -m pods + BRIEF=0 + TIMEOUT=15 + getopts :m:H:T:t:K:N:n:o:c:w:bh arg + case $arg in + export KUBECONFIG=/var/lib/nagios/kube_config + KUBECONFIG=/var/lib/nagios/kube_config + getopts :m:H:T:t:K:N:n:o:c:w:bh arg + case $arg in + MODE=pods + getopts :m:H:T:t:K:N:n:o:c:w:bh arg + '[' -z pods ']' + '[' '' ']' + command -v kubectl + command -v jq + OUTPUT= + EXITCODE=0 + kubectl_ns=--all-namespaces + '[' '' ']' + case "$MODE" in + mode_pods + WARN=30 + CRIT=150 + '[' 30 -gt 150 ']' + count_ready=0 + count_succeeded=0 + count_failed=0 + max_restart_count=0 + bad_container= ++ getJSON 'get pods --all-namespaces' api/v1/pods/ ++ kubectl_command='get pods --all-namespaces' ++ api_path=api/v1/pods/ ++ '[' '' ']' +++ timeout 15 kubectl 'get pods --all-namespaces' -o json ++ data='Error: unknown command "get pods --all-namespaces" for "kubectl" Run '\''kubectl --help'\'' for usage. unknown command "get pods --all-namespaces" for "kubectl"' ++ code=1 ++ '[' 1 -gt 0 ']' ++ '[' 1 = 124 ']' ++ die 'Error: unknown command "get pods --all-namespaces" for "kubectl" Run '\''kubectl --help'\'' for usage. unknown command "get pods --all-namespaces" for "kubectl"' ++ '[' 0 = 1 ']' ++ echo 'Error: unknown command "get pods --all-namespaces" for "kubectl" Run '\''kubectl --help'\'' for usage. unknown command "get pods --all-namespaces" for "kubectl"' ++ exit 2 + data='Error: unknown command "get pods --all-namespaces" for "kubectl" Run '\''kubectl --help'\'' for usage. unknown command "get pods --all-namespaces" for "kubectl"' + '[' 2 -gt 0 ']' + die 'Error: unknown command "get pods --all-namespaces" for "kubectl" Run '\''kubectl --help'\'' for usage. unknown command "get pods --all-namespaces" for "kubectl"' + '[' 0 = 1 ']' + echo 'Error: unknown command "get pods --all-namespaces" for "kubectl" Run '\''kubectl --help'\'' for usage. unknown command "get pods --all-namespaces" for "kubectl"' Error: unknown command "get pods --all-namespaces" for "kubectl" Run 'kubectl --help' for usage. unknown command "get pods --all-namespaces" for "kubectl" + exit 2
Removing the quotes and adding all command parts separately seems to fix the issue. I haven't seen any side-effects yet.
Thank you for pointing this out, but this issue has the right way for fixing it. The fix has been pushed to the repo.
Hi,
It seems the quotes around
$kubectl_command
causekubectl
to interpret the whole string as a single command. Leading to the following error.Removing the quotes and adding all command parts separately seems to fix the issue. I haven't seen any side-effects yet.