<commit_before>#!/bin/bash
# This script checks if dedicated-admin-operator is running, and send status to Zabbix.

# The following error handlers are below:
# Exit on error, trace the error, exit when unbound variables are used.
set -o errexit
set -o errtrace
set -o nounset

# Check the `ready` field of the dedicated-admin-operator pod.
ready="$(oc --kubeconfig=/tmp/admin.kubeconfig get pods -n openshift-dedicated-admin -l k8s-app=dedicated-admin-operator \
  --template='{{ range .items }}{{ (index .status.containerStatuses 0).ready }}{{"\n"}}{{ end }}')"

if $ready; then
  echo "Detected pod in 'ready' state."
  oc --kubeconfig=/tmp/admin.kubeconfig get pods -n openshift-dedicated-admin -l k8s-app=dedicated-admin-operator 
  echo "Sending zabbix metric:"
  echo "ops-metric-client -k openshift.master.service.dedicated.admin.count -o 1"
  ops-metric-client -k openshift.master.service.dedicated.admin.count -o 1
else
  echo "Detected pod is NOT in 'ready' state."
  oc --kubeconfig=/tmp/admin.kubeconfig get pods -n openshift-dedicated-admin -l k8s-app=dedicated-admin-operator 
  echo "Sending zabbix metric:"
  echo "ops-metric-client -k openshift.master.service.dedicated.admin.count -o 0"
  ops-metric-client -k openshift.master.service.dedicated.admin.count -o 0
fi<commit_msg>Add support for monitoring operator or script<commit_after>#!/bin/bash
# This script checks if dedicated-admin-operator is running, and send status to Zabbix.
# It also works with the legacy dedicated-admin script, so clusters that haven't been migrated
# to the operator yet will still have monitoring.

# The following error handlers are below:
# Exit on error, trace the error, exit when unbound variables are used.
set -o errexit
set -o errtrace
set -o nounset
trap 'echo "ERROR at line ${LINENO}"' ERR

function zabbix_ok {
  echo "Sending 'OK' to zabbix:"
  echo "ops-metric-client -k openshift.master.service.dedicated.admin.count -o 1"
  ops-metric-client -k openshift.master.service.dedicated.admin.count -o 1
}

function zabbix_not_ok {
  echo "Dedicated admin is not running on this host. Sending 'not OK' to zabbix:"
  echo "ops-metric-client -k openshift.master.service.dedicated.admin.count -o 0"
  ops-metric-client -k openshift.master.service.dedicated.admin.count -o 0
}

# Check the `ready` field of the dedicated-admin-operator pod.
echo "Checking for dedicated-admin-operator pod..."
pod_ready="$(oc --kubeconfig=/tmp/admin.kubeconfig get pods -n openshift-dedicated-admin -o=custom-columns=STATUS:.status.containerStatuses[*].ready --no-headers=true)"

if [ $pod_ready == "true" ]; then
  echo "Found dedicated-admin-operator pod in 'ready' state."
  zabbix_ok
else
  echo "Dedicated-admin-operator not found."
  echo "Checking for legacy dedicated-admin script..."
  echo -n "Number of processes running: "
  if pgrep -c -a -f /usr/bin/apply-dedicated-roles.py ; then
    echo "Found dedicated-admin process running."
    zabbix_ok
  else
    zabbix_not_ok
  fi
fi
{'fraction_non_alphanumeric': 0.11409395973154363, 'fraction_numerical': 0.004026845637583893, 'mean_word_length': 3.993299832495812, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2643489', 'n_tokens_mistral': 1001, 'n_tokens_neox': 953, 'n_words': 315}