#!/bin/bash
#
# Univention Nagios Plugin
#
# SPDX-FileCopyrightText: 2010-2025 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only

nagiosExit () {

	local state="$1"
	local msg="$2"

	case $state in
	0)
		echo "OK: $msg"
		exit 0
		;;
	1)
		echo "WARNING: $msg"
		exit 1
		;;
	2)
		echo "CRITICAL: $msg"
		exit 2
		;;
	*)
		echo "UNKNOWN: $msg"
		exit 3
		;;
	esac
}

if [ "$1" = "-h" -o "$1" = "--help" ] ; then
	echo "$0 checks local service 'cups'"
	echo "syntax: $0 [--help]"
	exit 3
fi


# check for at least one cupsd process
MSG="$(/usr/lib/nagios/plugins/check_procs -w 1: -c 1: -C cupsd)"
RET="$?"
if [ ! "$RET" = "0" ] ; then
	nagiosExit "$RET" "$MSG"
fi

# check HTTP service
MSG="$(/usr/lib/nagios/plugins/check_http -H "127.0.0.1:631" -I 127.0.0.1 -p 631 -S)"
nagiosExit "$?" "$MSG"
