Skip to content

Commit

Permalink
Merge pull request #148 from madrisan/podman-3.0-api
Browse files Browse the repository at this point in the history
feat: Podman 3.0+ API support
  • Loading branch information
madrisan authored Apr 1, 2024
2 parents 6c4f040 + b6204da commit 4b24db3
Show file tree
Hide file tree
Showing 31 changed files with 702 additions and 1,830 deletions.
12 changes: 2 additions & 10 deletions .github/workflows/build-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,14 @@ jobs:
;;
fedora*)
dnf -y update
dnf -y install autoconf automake bzip2 diffutils gcc glibc-devel libcurl-devel libvarlink-devel libtool make m4 systemd-devel xz
dnf -y install autoconf automake bzip2 diffutils gcc glibc-devel libcurl-devel libtool make m4 systemd-devel xz
;;
esac
- id: configure
run: |
autoreconf --install
case "${{ matrix.container }}" in
alpine*|debian*|gentoo*|ubuntu*)
./configure --enable-libcurl --enable-debug
;;
# libvarlink is only available in Fedora
*)
./configure --enable-libcurl --enable-libvarlink --enable-debug
;;
esac
./configure --enable-libcurl --enable-debug
- id: make
run: |
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
Here is the list of the available plugins:

* **check_clock** - returns the number of seconds elapsed between local time and Nagios server time
* **check_container** - checks the number of running docker/podman containers (:warning: *pre-alpha*, requires *libcurl* version 7.40.0+)
* **check_cpu** - checks the CPU (user mode) utilization
* **check_cpufreq** - displays the CPU frequency characteristics
* **check_cswch** - checks the total number of context switches across all CPUs
* **check_docker** - checks the number of running docker containers (:warning: *pre-alpha*, requires *libcurl* version 7.40.0+)
* **check_fc** - monitors the status of the fiber status ports
* **check_filecount** - checks the number of files found in one or more directories :new:
* **check_ifmountfs** - checks whether the given filesystems are mounted
Expand All @@ -36,7 +36,6 @@ Here is the list of the available plugins:
* check_network_multicast
* **check_paging** - checks the memory and swap paging
* **check_pressure** - checks Linux Pressure Stall Information (PSI) data :new:
* **check_podman** - monitor the status of podman containers (:warning: *alpha*, requires *libvarlink*)
* **check_readonlyfs** - checks for readonly filesystems
* **check_swap** - checks the swap usage
* **check_tcpcount** - checks the tcp network usage
Expand Down Expand Up @@ -156,7 +155,7 @@ The plugins are available [in the Gentoo tree](https://packages.gentoo.org/packa
```
emerge -av net-analyzer/nagios-plugins-linux-madrisan
```
The USE flags `curl` and `varlink` are required to respectively build `check_docker` and `check_podman`.
The USE flag `curl` is required to build `check_container`.

## Bugs

Expand Down
39 changes: 10 additions & 29 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -346,18 +346,6 @@ AS_IF([test "x$enable_libcurl" = "xyes"], [
AM_CONDITIONAL(HAVE_LIBCURL, [test "$libcurl_cv_lib_curl_usable" = "yes"])
], [AM_CONDITIONAL(HAVE_LIBCURL, false)])

dnl Check for libvarlink
AC_ARG_ENABLE([libvarlink],
AS_HELP_STRING([--enable-libvarlink], [enable libvarlink]))
AS_IF([test "x$enable_libvarlink" = "xyes"], [
PKG_CHECK_EXISTS([libvarlink],
[PKG_CHECK_MODULES(LIBVARLINK, [libvarlink >= 18],
[AC_DEFINE(HAVE_LIBVARLINK, 1, [Define if libvarlink is available])
have_libvarlink=yes],
[AC_MSG_ERROR([*** libvarlink version 18 or better not found])])],
[AC_MSG_ERROR([*** libvarlink not found])])])
AM_CONDITIONAL(HAVE_LIBVARLINK, [test "$have_libvarlink" = "yes"])

dnl Check for the procps newlib
have_libprocps=no
AC_ARG_ENABLE([libprocps],
Expand Down Expand Up @@ -433,16 +421,16 @@ AC_ARG_WITH(
[DOCKER_SOCKET="$with_dockersocket"])
AC_SUBST(DOCKER_SOCKET)

dnl Add the option: '--with-varlink-address'
VARLINK_ADDRESS="unix:/run/podman/io.podman"
dnl Add the option: '--with-podman-socket'
PODMAN_SOCKET="/run/podman/podman.sock"
AC_ARG_WITH(
[varlinkaddress],
[podmansocket],
[AS_HELP_STRING(
[--with-varlink-address],
[use a different address for varlink socket
(default is unix:/run/podman/io.podman)])],
[VARLINK_ADDRESS="$with_varlinkaddress"])
AC_SUBST(VARLINK_ADDRESS)
[--with-podman-socket],
[use a different podman socket
(default is /run/podman/podman.sock)])],
[PODMAN_SOCKET="$with_podmansocket"])
AC_SUBST(PODMAN_SOCKET)

dnl Add the option: '--with-socketfile'
MULTIPATHD_SOCKET="@/org/kernel/linux/storage/multipathd"
Expand Down Expand Up @@ -572,6 +560,7 @@ echo " hardening enabled = $use_hardening"
echo " werror enabled = $enable_werror"
echo " with docker socket = $DOCKER_SOCKET"
echo " with libprocps = $enable_libprocps"
echo " with podman socket = $PODMAN_SOCKET"
echo " with socketfile = $MULTIPATHD_SOCKET"
echo " with test suite = $with_test_suite"
echo
Expand All @@ -591,20 +580,12 @@ if test "$have_libprocps" = "yes"; then
fi

if test "$libcurl_cv_lib_curl_usable" = "yes"; then
echo "Optional curl library support is enabled (required by check_docker):"
echo "Optional curl library support is enabled (required by check_container):"
echo " LIBCURL_CPPFLAGS = $LIBCURL_CPPFLAGS"
echo " LIBCURL = $LIBCURL"
echo
fi

if test "$have_libvarlink" = "yes"; then
echo "Optional varlink library support is enabled (required by check_podman):"
echo " LIBVARLINK_CFLAGS = $LIBVARLINK_CFLAGS"
echo " LIBVARLINK_LIBS = -lvarlink"
echo " VARLINK_ADDRESS = $VARLINK_ADDRESS"
echo
fi

if test "$have_systemd" = "yes"; then
echo "Optional systemd library support is enabled:"
echo " SYSTEMD_CFLAGS = $SYSTEMD_CFLAGS"
Expand Down
2 changes: 1 addition & 1 deletion debian/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ EXTRA_DIST = changelog compat control copyright rules \
source/format \
nagios-plugins-linux.dirs \
nagios-plugins-linux-clock.install \
nagios-plugins-linux-container.install \
nagios-plugins-linux-cpufreq.install \
nagios-plugins-linux-cpu.install \
nagios-plugins-linux-cswch.install \
nagios-plugins-linux.dirs \
nagios-plugins-linux-docker.install \
nagios-plugins-linux-fc.install \
nagios-plugins-linux-ifmountfs.install \
nagios-plugins-linux-intr.install \
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
nagios-plugins-linux (32-1) stable; urgency=low
* Release 32 "Gematria":
- Fixes in check_network, check_users, and check_cpufreq.

-- Davide Madrisan <[email protected]> Thu, 25 Jan 2024 22:44:00 +0200

nagios-plugins-linux (31-1) stable; urgency=low
* Release 31 "Counter-intuitive":
- New plugin check_filecount
Expand Down
8 changes: 4 additions & 4 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ Description: Linux plugins for nagios compatible monitoring systems
Package: nagios-plugins-linux-experimental
Architecture: any
Depends: ${misc:Depends},
nagios-plugins-linux-docker
nagios-plugins-linux-container
Suggests: nagios3 | icinga | icinga2
Description: Linux plugins for nagios compatible monitoring systems
Experimental plugins for nagios compatible monitoring systems like Naemon and
Icinga. It contains the following plugins:
.
check_docker
check_container
.
This package provides some experimental plugins that are most likely to be
useful on a central monitoring host.
Expand Down Expand Up @@ -98,14 +98,14 @@ Description: Linux plugins for nagios compatible monitoring systems
.
This plugin monitors the total number of context switches per second across all CPUs.

Package: nagios-plugins-linux-docker
Package: nagios-plugins-linux-container
Architecture: any
Depends: ${misc:Depends}, ${shlibs:Depends}
Suggests: nagios3 | icinga | icinga2
Description: Linux plugins for nagios compatible monitoring systems
A suite of Nagios/NRPE plugins for monitoring Linux servers and appliances.
.
This plugin checks the number of running docker containers.
This plugin performs basic monitoring for docker and podman containers.

Package: nagios-plugins-linux-fc
Architecture: any
Expand Down
1 change: 1 addition & 0 deletions debian/nagios-plugins-linux-container.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/lib/nagios/plugins/check_container
1 change: 0 additions & 1 deletion debian/nagios-plugins-linux-docker.install

This file was deleted.

5 changes: 2 additions & 3 deletions include/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in

## Copyright (c) 2014-2016 Davide Madrisan <[email protected]>
## Copyright (c) 2014-2024 Davide Madrisan <[email protected]>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
Expand All @@ -20,8 +20,7 @@ AM_CPPFLAGS = -include $(top_builddir)/config.h
noinst_HEADERS = \
collection.h \
common.h \
container_docker.h \
container_podman.h \
container.h \
cpudesc.h \
cpufreq.h \
cpustats.h \
Expand Down
8 changes: 6 additions & 2 deletions include/container_docker.h → include/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ extern "C"
long long docker_memory_get_total_pgpgout (
struct docker_memory_desc *memdesc);

int docker_running_containers (unsigned int *count, const char *image,
char **perfdata, bool verbose);
int docker_running_containers (char *socket, unsigned int *count,
const char *image, char **perfdata,
bool verbose);
int docker_running_containers_memory (char *socket,
long long unsigned int *memory,
bool verbose);

#ifdef __cplusplus
}
Expand Down
118 changes: 0 additions & 118 deletions include/container_podman.h

This file was deleted.

2 changes: 2 additions & 0 deletions include/json_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ extern "C"
int json_token_streq (const char *json, jsmntok_t * tok, const char *s);
char *json_token_tostr (char *json, jsmntok_t * t);
jsmntok_t *json_tokenise (const char *json, size_t *ntoken);
void json_dump_pretty (const char *json, char **dump, int indent);
int json_search (const char *json, const char *path, char **value);

#ifdef __cplusplus
}
Expand Down
14 changes: 3 additions & 11 deletions lib/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in

## Copyright (c) 2014-2016 Davide Madrisan <[email protected]>
## Copyright (c) 2014-2024 Davide Madrisan <[email protected]>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
Expand All @@ -19,15 +19,14 @@ AM_CPPFLAGS = \
-include $(top_builddir)/config.h \
-I$(top_srcdir)/include \
-DDOCKER_SOCKET=\"$(DOCKER_SOCKET)\" \
-DVARLINK_ADDRESS=\"$(VARLINK_ADDRESS)\" \
-DPODMAN_SOCKET=\"$(PODMAN_SOCKET)\" \
$(LIBCURL_CPPFLAGS) \
$(LIBPROCPS_CPPFLAGS)

noinst_LIBRARIES = libutils.a

libutils_a_SOURCES = \
collection.c \
container_docker_memory.c \
cpudesc.c \
cpufreq.c \
cpustats.c \
Expand Down Expand Up @@ -55,14 +54,7 @@ libutils_a_SOURCES = \

if HAVE_LIBCURL
libutils_a_SOURCES += \
container_docker_count.c
endif

if HAVE_LIBVARLINK
libutils_a_SOURCES += \
container_podman.c \
container_podman_count.c \
container_podman_stats.c
container.c
endif

if HAVE_LIBPROCPS
Expand Down
1 change: 1 addition & 0 deletions lib/collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ counter_lookup (const hashtable_t * hashtable, const char *key)
{
hashable_t *np;

dbg ("hashtable lookup for key \"%s\"\n", key);
for (np = hashtable->table[hash (key)]; np != NULL; np = np->next)
if (STREQ (key, np->key))
{
Expand Down
Loading

0 comments on commit 4b24db3

Please sign in to comment.