Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement health check registry #29

Open
gregbugaj opened this issue Aug 15, 2022 · 0 comments
Open

Implement health check registry #29

gregbugaj opened this issue Aug 15, 2022 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@gregbugaj
Copy link
Collaborator

gregbugaj commented Aug 15, 2022

Implement health check registry.

Registry needs to support following types:

  • http
  • script
  • tcp
  • sql

Example configuration:

monitor.json

{
  "shell" :"/bin/bash",
  "args": [
    "./monitor/memory.sh"
  ],
  "id": "pan.memory.0",
  "name": "pan.memory",
  "interval": "PT1M",
  "ttl": "PT1M",
  "timeout": "PT10S",
  "tags": [
    "agent",
    "system",
    "pan",
    "memory"
  ],

    "webhooks": [
      {
        "name": "",
        "uri": "",
        "payload": "",
      }
    ],

  "__type__": "script"
}

Webhooks: If any health check returns a Failure result, this collections will be used to notify the error status. (Payload is the json payload and must be escaped.)

memory.sh

#!/bin/bash

process="SAMPLE"

# percentage
failureval=95
critivalval=90

total_memory=$(free | grep Mem: | awk '{print $2}')
used_memory=$(free | grep buffers/cache: | awk '{print $3}')
memory_use=`echo $used_memory $total_memory | awk '{print $1 / $2 * 100}'`
memory_use=${memory_use%%.*}

printf "Checking $process memory on $(hostname -i)... "

if [ "$memory_use" -ge "$failureval" ]; then
    echo "FAILED. $memory_use%."
    exit 2
elif [ "$memory_use" -ge "$critivalval" ]; then
    echo "CRITICAL. $memory_use%."
    exit 1
elif [ "$memory_use" -le "$critivalval" ]; then
    echo "PASSED. $memory_use%."
    exit 0
fi

echo "Memory use could not be determined."
exit 2

Shell scripts will have following error codes:
0 = Passed
1 = Critical
2 = Failed

Example:

if [ "$memory_use" -ge "$failureval" ]; then
    echo "FAILED. $memory_use%."
    exit 2
elif [ "$memory_use" -ge "$critivalval" ]; then
    echo "CRITICAL. $memory_use%."
    exit 1
elif [ "$memory_use" -le "$critivalval" ]; then
    echo "PASSED. $memory_use%."
    exit 0
fi
@gregbugaj gregbugaj added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant