Created
September 3, 2019 11:35
-
-
Save mika/a08cb109a601bea9e943aab9ada9691b to your computer and use it in GitHub Desktop.
modules/profile/files/monitoring/local/check_jenkins_plugins
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# HEADER: managed by puppet, do NOT edit manually! | |
set -u | |
if [ ! -e /lib/systemd/system/jenkins.service ] ; then | |
# Check should be enabled only on jenkins master hosts | |
exit 0 | |
fi | |
script=$(basename "$(readlink -f "$0")") | |
if pgrep -f list-plugins >/dev/null; then | |
result="Check is already running" | |
rc=1 | |
else | |
cli=/var/lib/jenkins/jenkins-cli.jar | |
# shellcheck disable=SC2016 | |
awk_script='BEGIN {ORS=", "} { if ( $NF ~ /^\(/ ) print $1}' | |
updates=$(java -jar ${cli} -ssh -user jenkins -i /var/lib/jenkins/.ssh/id_rsa_jenkins -s http://localhost:8080 list-plugins | awk "${awk_script}") | |
if [ -n "${updates:-}" ] ; then | |
num=$(echo "${updates}" | wc -w) | |
result="Plugin updates (${num}): ${updates}" | |
rc=1 | |
else | |
result="No plugin updates" | |
rc=0 | |
fi | |
fi | |
echo "${rc:-2} ${script} - ${result:-UNKNOWN ERROR}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment