Skip to content

Commit

Permalink
Added the nagios .deb config file.
Browse files Browse the repository at this point in the history
  • Loading branch information
swapnil110399 committed Jul 3, 2024
1 parent 0e9ef54 commit d59db5d
Show file tree
Hide file tree
Showing 9 changed files with 1,381 additions and 0 deletions.
9 changes: 9 additions & 0 deletions nagios-plugins-ets-1.4/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Package: nagios-plugins-ets
Version: 1.4
Section: utils
Priority: optional
Architecture: all
Depends: python3-psutil, smartmontools
Maintainer: Your Name <[email protected]>
Description: Nagios plugins for system monitoring
Collection of Nagios plugins for system monitoring, including memory check, smartmon, zpools, and service checks.
3 changes: 3 additions & 0 deletions nagios-plugins-ets-1.4/DEBIAN/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
chmod 755 /usr/lib64/nagios/plugins/*

127 changes: 127 additions & 0 deletions nagios-plugins-ets-1.4/check_mem.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#include <ctype.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <unistd.h>

#define INVAL_SIZE UINT64_C(0xFFFFFFFFFFFFFFFF)

struct mem_stats
{
uint64_t total_kB;
uint64_t avail_kB;
uint64_t free_kB;
uint64_t buffers_kB;
uint64_t cached_kB;
uint64_t used_kB;
};

static void dump_mem_stats(struct mem_stats *mem_stats)
{
FILE *fp;
char line[1024];
unsigned int i;
char *nptr;

fp = fopen("/proc/meminfo", "r");

mem_stats->total_kB = INVAL_SIZE;
mem_stats->avail_kB = INVAL_SIZE;
mem_stats->free_kB = INVAL_SIZE;
mem_stats->buffers_kB = INVAL_SIZE;
mem_stats->cached_kB = INVAL_SIZE;
mem_stats->used_kB = INVAL_SIZE;

while (!feof(fp) && !ferror(fp))
{
if (!fgets(line, sizeof(line), fp))
continue;

if (strncmp(&line[0], "MemTotal:", 9) == 0)
{
mem_stats->total_kB = strtoull(&line[9], &nptr, 10);
continue;
}

if (strncmp(&line[0], "MemAvailable:", 13) == 0)
{
mem_stats->avail_kB = strtoull(&line[13], &nptr, 10);
continue;
}

if (strncmp(&line[0], "memFree:", 8) == 0)
{
mem_stats->free_kB = strtoull(&line[8], &nptr, 10);
continue;
}

if (strncmp(&line[0], "Buffers:", 8) == 0)
{
mem_stats->buffers_kB = strtoull(&line[8], &nptr, 10);
continue;
}

if (strncmp(&line[0], "Cached:", 7) == 0)
{
mem_stats->cached_kB = strtoull(&line[7], &nptr, 10);
continue;
}
}

fclose(fp);

if (mem_stats->avail_kB == INVAL_SIZE)
{
mem_stats->avail_kB = 0;

if (mem_stats->free_kB != INVAL_SIZE)
mem_stats->avail_kB += mem_stats->free_kB;

if (mem_stats->buffers_kB != INVAL_SIZE)
mem_stats->avail_kB += mem_stats->buffers_kB;

if (mem_stats->cached_kB != INVAL_SIZE)
mem_stats->avail_kB += mem_stats->cached_kB;
}

if (mem_stats->used_kB == INVAL_SIZE)
mem_stats->used_kB = mem_stats->total_kB - mem_stats->avail_kB;
}

int main(int argc, char **argv)
{
int result;
float warn_threshold;
float crit_threshold;
struct mem_stats stats;
float mem_pct;
const char *panic_str;

/* cmd line : $0 -w warn_threshold -c crit_threshold */
warn_threshold = strtof(argv[2], NULL);
crit_threshold = strtof(argv[4], NULL);

dump_mem_stats(&stats);

mem_pct = 10000 * stats.used_kB / stats.total_kB / 100.f;

panic_str = "OK";
result = 0;
if (mem_pct >= crit_threshold)
{
panic_str = "Critical";
result = 2;
}
else if (mem_pct >= warn_threshold)
{
panic_str = "Warning";
result = 1;
}

printf("MEMORY %s - Used = %.2f%% | 'Total'=%" PRIu64 "MB 'Used'=%" PRIu64 "MB 'Free'=%" PRIu64 "MB\n", panic_str, mem_pct, stats.total_kB / 1024, stats.used_kB / 1024, stats.avail_kB / 1024);

return result;
}
Binary file not shown.
63 changes: 63 additions & 0 deletions nagios-plugins-ets-1.4/usr/lib64/nagios/plugins/check_service
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

#Author: Tino

#VARIABLES NAGIOS
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3

PROGNAME=`basename $0 .sh`
VERSION="Version 1.1"

print_version() {
echo "$VERSION"
}

print_help() {
print_version $PROGNAME $VERSION
echo ""
echo "$PROGNAME is a Nagios plugin to check a specific service using systemctl."
echo ""
echo "$PROGNAME -s <service_name>"
exit $UNKNOWN
}

if test -z "$1"
then
print_help
exit $CRITICAL
fi

while test -n "$1"; do
case "$1" in
--help|-h)
print_help
exit $UNKNOWN
;;
--version|-v)
print_version $PROGNAME $VERSION
exit $UNKNOWN
;;
--service|-s)
SERVICE=$2
shift
;;
*)
echo "Unknown argument: $1"
print_help
exit $UNKNOWN
;;
esac
shift
done

if systemctl is-active $SERVICE >/dev/null 2>&1
then
echo -e "OK: Service $SERVICE is running!"
exit $OK
else
echo -e "CRITICAL: Service $SERVICE is not running!"
exit $CRITICAL
fi
Loading

0 comments on commit d59db5d

Please sign in to comment.