cat /usr/lib64/nagios/plugins/check_zammadhelpdeskqueue.sh
#!/bin/bash
# https://gist.github.com/maxcnunes/9f77afdc32df354883df
# https://www.howtoforge.com/tutorial/write-a-custom-nagios-check-plugin/
URL="https://helpdesk.example.com/api/v1/tickets/search?query=owner.id%3A1%20AND%20group.id%3A1%20AND%20state.name%3A(%22new%22%20OR%20%22open%22%20OR%20%22pending%20reminder%22)"
BEARER="blablablatokengoeshere"

# store the whole response with the status at the and
HTTP_RESPONSE=$(curl --url $URL --header "Authorization: Bearer $BEARER" --silent --write-out "HTTPSTATUS:%{http_code}")
# extract the body, then extract ticket_count value from the JSON
HTTP_BODY=$(echo $HTTP_RESPONSE | sed -e 's/HTTPSTATUS\:.*//g' | jq '.tickets_count')

# extract the status
HTTP_STATUS=$(echo $HTTP_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')

# if HTTP status is 200 OK, then return ticket_count
if [ $HTTP_STATUS -eq 200 ]; then
  convert -size 550x275 -background none -fill white -gravity center -font Courier-Bold label:$HTTP_BODY /opt/librenms/html/images/helpdesk_queue.png
  convert -size 550x275 -gravity center -font Courier-Bold label:$HTTP_BODY /opt/librenms/html/images/helpdesk_queue.svg  echo "$HTTP_BODY tickets in Helpdesk queue with no Owner | 'tickets'=$HTTP_BODY"
  exit 0
fi

# if HTTP status is not 200 OK, exit  with warning state
if [ ! $HTTP_STATUS -eq 200  ]; then
  echo "Error [HTTP status: $HTTP_STATUS]"
  exit 2
