Merge pull request #1888 from thkukuk/no-utmp

check_users: prefer systemd-logind over utmp
This commit is contained in:
Lorenz Kästle 2023-08-28 15:09:34 +02:00 committed by GitHub
commit b90b09e147
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 94 additions and 62 deletions

View file

@ -328,6 +328,25 @@ AS_IF([test "x$with_ldap" != "xno"], [
LIBS="$_SAVEDLIBS"
])
AC_ARG_WITH([systemd], [AS_HELP_STRING([--without-systemd], [Skips systemd support])])
dnl Check for libsystemd
AS_IF([test "x$with_systemd" != "xno"], [
_SAVEDLIBS="$LIBS"
AC_CHECK_LIB(systemd,sd_get_sessions,,,-lsystemd)
if test "$ac_cv_lib_systemd_sd_get_sessions" = "yes"; then
SYSTEMDLIBS="-lsystemd"
SYSTEMDINCLUDE=""
AC_SUBST(SYSTEMDLIBS)
AC_SUBST(SYSTEMDINCLUDE)
else
AC_MSG_WARN([Skipping systemd support])
fi
LIBS="$_SAVEDLIBS"
])
dnl Check for headers used by check_ide_smart
case $host in
*linux*)

View file

@ -112,7 +112,7 @@ check_tcp_LDADD = $(SSLOBJS)
check_time_LDADD = $(NETLIBS)
check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS)
check_ups_LDADD = $(NETLIBS)
check_users_LDADD = $(BASEOBJS) $(WTSAPI32LIBS)
check_users_LDADD = $(BASEOBJS) $(WTSAPI32LIBS) $(SYSTEMDLIBS)
check_by_ssh_LDADD = $(NETLIBS)
check_ide_smart_LDADD = $(BASEOBJS)
negate_LDADD = $(BASEOBJS)

View file

@ -1,33 +1,33 @@
/*****************************************************************************
*
*
* Monitoring check_users plugin
*
*
* License: GPL
* Copyright (c) 2000-2012 Monitoring Plugins Development Team
*
*
* Description:
*
*
* This file contains the check_users plugin
*
*
* This plugin checks the number of users currently logged in on the local
* system and generates an error if the number exceeds the thresholds
* specified.
*
*
*
*
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*
*
*****************************************************************************/
const char *progname = "check_users";
@ -48,6 +48,11 @@ const char *email = "devel@monitoring-plugins.org";
# include "popen.h"
#endif
#ifdef HAVE_LIBSYSTEMD
#include <systemd/sd-daemon.h>
#include <systemd/sd-login.h>
#endif
#define possibly_set(a,b) ((a) == 0 ? (b) : 0)
int process_arguments (int, char **);
@ -85,6 +90,11 @@ main (int argc, char **argv)
users = 0;
#ifdef HAVE_LIBSYSTEMD
if (sd_booted () > 0)
users = sd_get_sessions (NULL);
else {
#endif
#if HAVE_WTSAPI32_H
if (!WTSEnumerateSessions(WTS_CURRENT_SERVER_HANDLE,
0, 1, &wtsinfo, &wtscount)) {
@ -156,6 +166,9 @@ main (int argc, char **argv)
if (spclose (child_process))
result = possibly_set (result, STATE_UNKNOWN);
#endif
#ifdef HAVE_LIBSYSTEMD
}
#endif
/* check the user count against warning and critical thresholds */
result = get_status((double)users, thlds);
@ -163,7 +176,7 @@ main (int argc, char **argv)
if (result == STATE_UNKNOWN)
printf ("%s\n", _("Unable to read output"));
else {
printf (_("USERS %s - %d users currently logged in |%s\n"),
printf (_("USERS %s - %d users currently logged in |%s\n"),
state_text(result), users,
sperfdata_int("users", users, "", warning_range,
critical_range, TRUE, 0, FALSE, 0));

View file

@ -9,7 +9,7 @@ msgid ""
msgstr ""
"Project-Id-Version: nagiosplug\n"
"Report-Msgid-Bugs-To: devel@monitoring-plugins.org\n"
"POT-Creation-Date: 2023-07-11 16:07+0200\n"
"POT-Creation-Date: 2023-08-28 14:50+0200\n"
"PO-Revision-Date: 2004-12-23 17:46+0100\n"
"Last-Translator: <>\n"
"Language-Team: English <en@li.org>\n"
@ -31,7 +31,7 @@ msgstr ""
#: plugins/check_radius.c:176 plugins/check_real.c:80 plugins/check_smtp.c:146
#: plugins/check_snmp.c:248 plugins/check_ssh.c:74 plugins/check_swap.c:115
#: plugins/check_tcp.c:222 plugins/check_time.c:78 plugins/check_ups.c:122
#: plugins/check_users.c:84 plugins/negate.c:210 plugins-root/check_dhcp.c:270
#: plugins/check_users.c:89 plugins/negate.c:210 plugins-root/check_dhcp.c:270
msgid "Could not parse arguments"
msgstr "Argumente konnten nicht ausgewertet werden"
@ -255,7 +255,7 @@ msgstr ""
#: plugins/check_radius.c:400 plugins/check_real.c:452 plugins/check_smtp.c:891
#: plugins/check_snmp.c:1347 plugins/check_ssh.c:325 plugins/check_swap.c:607
#: plugins/check_tcp.c:710 plugins/check_time.c:371 plugins/check_ups.c:663
#: plugins/check_users.c:262 plugins/check_ide_smart.c:606 plugins/negate.c:273
#: plugins/check_users.c:275 plugins/check_ide_smart.c:606 plugins/negate.c:273
#: plugins/urlize.c:196 plugins-root/check_dhcp.c:1390
#: plugins-root/check_icmp.c:1633
msgid "Usage:"
@ -892,13 +892,13 @@ msgid "of the <state> argument with optional text"
msgstr ""
#: plugins/check_fping.c:127 plugins/check_hpjd.c:134 plugins/check_ping.c:444
#: plugins/check_swap.c:193 plugins/check_users.c:130 plugins/urlize.c:109
#: plugins/check_swap.c:193 plugins/check_users.c:140 plugins/urlize.c:109
#, c-format
msgid "Could not open pipe: %s\n"
msgstr "Pipe: %s konnte nicht geöffnet werden\n"
#: plugins/check_fping.c:133 plugins/check_hpjd.c:140 plugins/check_load.c:159
#: plugins/check_swap.c:199 plugins/check_users.c:136 plugins/urlize.c:115
#: plugins/check_swap.c:199 plugins/check_users.c:146 plugins/urlize.c:115
#, c-format
msgid "Could not open stderr for %s\n"
msgstr "Konnte stderr nicht öffnen für: %s\n"
@ -3688,12 +3688,12 @@ msgid " %s - database %s (%f sec.)|%s\n"
msgstr ""
#: plugins/check_pgsql.c:320 plugins/check_time.c:277 plugins/check_time.c:289
#: plugins/check_users.c:228
#: plugins/check_users.c:241
msgid "Critical threshold must be a positive integer"
msgstr "Critical threshold muss ein positiver Integer sein"
#: plugins/check_pgsql.c:326 plugins/check_time.c:258 plugins/check_time.c:282
#: plugins/check_users.c:226
#: plugins/check_users.c:239
msgid "Warning threshold must be a positive integer"
msgstr "Warning threshold muss ein positiver Integer sein"
@ -5668,26 +5668,26 @@ msgstr ""
msgid "http://www.networkupstools.org"
msgstr ""
#: plugins/check_users.c:91
#: plugins/check_users.c:101
#, fuzzy, c-format
msgid "Could not enumerate RD sessions: %d\n"
msgstr "Konnte·url·nicht·zuweisen\n"
#: plugins/check_users.c:146
#: plugins/check_users.c:156
#, c-format
msgid "# users=%d"
msgstr ""
#: plugins/check_users.c:164
#: plugins/check_users.c:177
msgid "Unable to read output"
msgstr ""
#: plugins/check_users.c:166
#: plugins/check_users.c:179
#, c-format
msgid "USERS %s - %d users currently logged in |%s\n"
msgstr ""
#: plugins/check_users.c:241
#: plugins/check_users.c:254
#, fuzzy
msgid "This plugin checks the number of users currently logged in on the local"
msgstr ""
@ -5696,16 +5696,16 @@ msgstr ""
"unterschritten wird.\n"
"\n"
#: plugins/check_users.c:242
#: plugins/check_users.c:255
msgid ""
"system and generates an error if the number exceeds the thresholds specified."
msgstr ""
#: plugins/check_users.c:252
#: plugins/check_users.c:265
msgid "Set WARNING status if more than INTEGER users are logged in"
msgstr ""
#: plugins/check_users.c:254
#: plugins/check_users.c:267
msgid "Set CRITICAL status if more than INTEGER users are logged in"
msgstr ""

View file

@ -10,7 +10,7 @@ msgid ""
msgstr ""
"Project-Id-Version: fr\n"
"Report-Msgid-Bugs-To: devel@monitoring-plugins.org\n"
"POT-Creation-Date: 2023-07-11 16:07+0200\n"
"POT-Creation-Date: 2023-08-28 14:50+0200\n"
"PO-Revision-Date: 2010-04-21 23:38-0400\n"
"Last-Translator: Thomas Guyot-Sionnest <dermoth@aei.ca>\n"
"Language-Team: Nagios Plugin Development Mailing List <nagiosplug-"
@ -34,7 +34,7 @@ msgstr ""
#: plugins/check_radius.c:176 plugins/check_real.c:80 plugins/check_smtp.c:146
#: plugins/check_snmp.c:248 plugins/check_ssh.c:74 plugins/check_swap.c:115
#: plugins/check_tcp.c:222 plugins/check_time.c:78 plugins/check_ups.c:122
#: plugins/check_users.c:84 plugins/negate.c:210 plugins-root/check_dhcp.c:270
#: plugins/check_users.c:89 plugins/negate.c:210 plugins-root/check_dhcp.c:270
msgid "Could not parse arguments"
msgstr "Impossible de décomposer les arguments"
@ -261,7 +261,7 @@ msgstr "Exemples:"
#: plugins/check_radius.c:400 plugins/check_real.c:452 plugins/check_smtp.c:891
#: plugins/check_snmp.c:1347 plugins/check_ssh.c:325 plugins/check_swap.c:607
#: plugins/check_tcp.c:710 plugins/check_time.c:371 plugins/check_ups.c:663
#: plugins/check_users.c:262 plugins/check_ide_smart.c:606 plugins/negate.c:273
#: plugins/check_users.c:275 plugins/check_ide_smart.c:606 plugins/negate.c:273
#: plugins/urlize.c:196 plugins-root/check_dhcp.c:1390
#: plugins-root/check_icmp.c:1633
msgid "Usage:"
@ -929,13 +929,13 @@ msgid "of the <state> argument with optional text"
msgstr "du paramètre <state> avec un texte optionnel"
#: plugins/check_fping.c:127 plugins/check_hpjd.c:134 plugins/check_ping.c:444
#: plugins/check_swap.c:193 plugins/check_users.c:130 plugins/urlize.c:109
#: plugins/check_swap.c:193 plugins/check_users.c:140 plugins/urlize.c:109
#, c-format
msgid "Could not open pipe: %s\n"
msgstr "Impossible d'ouvrir le pipe: %s\n"
#: plugins/check_fping.c:133 plugins/check_hpjd.c:140 plugins/check_load.c:159
#: plugins/check_swap.c:199 plugins/check_users.c:136 plugins/urlize.c:115
#: plugins/check_swap.c:199 plugins/check_users.c:146 plugins/urlize.c:115
#, c-format
msgid "Could not open stderr for %s\n"
msgstr "Impossible d'ouvrir la sortie d'erreur standard pour %s\n"
@ -1495,8 +1495,8 @@ msgstr ""
#, fuzzy, c-format
msgid "HTTP CRITICAL - redirection creates an infinite loop - %s://%s:%d%s%s\n"
msgstr ""
"HTTP AVERTISSEMENT - la redirection crée une boucle infinie - %s://%s:"
"%d%s%s\n"
"HTTP AVERTISSEMENT - la redirection crée une boucle infinie - %s://%s:%d%s"
"%s\n"
#: plugins/check_http.c:1630
#, c-format
@ -3084,8 +3084,8 @@ msgstr ""
#: plugins/check_ntp_peer.c:716
msgid "Critical threshold for number of usable time sources (\"truechimers\")"
msgstr ""
"Seuil critique pour le nombre de sources de temps utilisable "
"(\"truechimers\")"
"Seuil critique pour le nombre de sources de temps utilisable (\"truechimers"
"\")"
#: plugins/check_ntp_peer.c:721
msgid "This plugin checks an NTP server independent of any commandline"
@ -3751,12 +3751,12 @@ msgid " %s - database %s (%f sec.)|%s\n"
msgstr " %s - base de données %s (%d sec.)|%s\n"
#: plugins/check_pgsql.c:320 plugins/check_time.c:277 plugins/check_time.c:289
#: plugins/check_users.c:228
#: plugins/check_users.c:241
msgid "Critical threshold must be a positive integer"
msgstr "Le seuil critique doit être un entier positif"
#: plugins/check_pgsql.c:326 plugins/check_time.c:258 plugins/check_time.c:282
#: plugins/check_users.c:226
#: plugins/check_users.c:239
msgid "Warning threshold must be a positive integer"
msgstr "Le seuil d'avertissement doit être un entier positif"
@ -5774,43 +5774,43 @@ msgstr ""
msgid "http://www.networkupstools.org"
msgstr ""
#: plugins/check_users.c:91
#: plugins/check_users.c:101
#, fuzzy, c-format
msgid "Could not enumerate RD sessions: %d\n"
msgstr "Impossible d'utiliser le protocole version %d\n"
#: plugins/check_users.c:146
#: plugins/check_users.c:156
#, c-format
msgid "# users=%d"
msgstr "# utilisateurs=%d"
#: plugins/check_users.c:164
#: plugins/check_users.c:177
msgid "Unable to read output"
msgstr "Impossible de lire les données en entrée"
#: plugins/check_users.c:166
#: plugins/check_users.c:179
#, c-format
msgid "USERS %s - %d users currently logged in |%s\n"
msgstr "UTILISATEURS %s - %d utilisateurs actuellement connectés sur |%s\n"
#: plugins/check_users.c:241
#: plugins/check_users.c:254
msgid "This plugin checks the number of users currently logged in on the local"
msgstr ""
"Ce plugin vérifie le nombre d'utilisateurs actuellement connecté sur le "
"système local"
#: plugins/check_users.c:242
#: plugins/check_users.c:255
msgid ""
"system and generates an error if the number exceeds the thresholds specified."
msgstr "et génère une erreur si le nombre excède le seuil spécifié."
#: plugins/check_users.c:252
#: plugins/check_users.c:265
msgid "Set WARNING status if more than INTEGER users are logged in"
msgstr ""
"Sortir avec un résultat AVERTISSEMENT si plus de INTEGER utilisateurs sont "
"connectés"
#: plugins/check_users.c:254
#: plugins/check_users.c:267
msgid "Set CRITICAL status if more than INTEGER users are logged in"
msgstr ""
"Sortir avec un résultat CRITIQUE si plus de INTEGER utilisateurs sont "

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: devel@monitoring-plugins.org\n"
"POT-Creation-Date: 2023-07-11 16:07+0200\n"
"POT-Creation-Date: 2023-08-28 14:50+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -30,7 +30,7 @@ msgstr ""
#: plugins/check_radius.c:176 plugins/check_real.c:80 plugins/check_smtp.c:146
#: plugins/check_snmp.c:248 plugins/check_ssh.c:74 plugins/check_swap.c:115
#: plugins/check_tcp.c:222 plugins/check_time.c:78 plugins/check_ups.c:122
#: plugins/check_users.c:84 plugins/negate.c:210 plugins-root/check_dhcp.c:270
#: plugins/check_users.c:89 plugins/negate.c:210 plugins-root/check_dhcp.c:270
msgid "Could not parse arguments"
msgstr ""
@ -246,7 +246,7 @@ msgstr ""
#: plugins/check_radius.c:400 plugins/check_real.c:452 plugins/check_smtp.c:891
#: plugins/check_snmp.c:1347 plugins/check_ssh.c:325 plugins/check_swap.c:607
#: plugins/check_tcp.c:710 plugins/check_time.c:371 plugins/check_ups.c:663
#: plugins/check_users.c:262 plugins/check_ide_smart.c:606 plugins/negate.c:273
#: plugins/check_users.c:275 plugins/check_ide_smart.c:606 plugins/negate.c:273
#: plugins/urlize.c:196 plugins-root/check_dhcp.c:1390
#: plugins-root/check_icmp.c:1633
msgid "Usage:"
@ -870,13 +870,13 @@ msgid "of the <state> argument with optional text"
msgstr ""
#: plugins/check_fping.c:127 plugins/check_hpjd.c:134 plugins/check_ping.c:444
#: plugins/check_swap.c:193 plugins/check_users.c:130 plugins/urlize.c:109
#: plugins/check_swap.c:193 plugins/check_users.c:140 plugins/urlize.c:109
#, c-format
msgid "Could not open pipe: %s\n"
msgstr ""
#: plugins/check_fping.c:133 plugins/check_hpjd.c:140 plugins/check_load.c:159
#: plugins/check_swap.c:199 plugins/check_users.c:136 plugins/urlize.c:115
#: plugins/check_swap.c:199 plugins/check_users.c:146 plugins/urlize.c:115
#, c-format
msgid "Could not open stderr for %s\n"
msgstr ""
@ -3592,12 +3592,12 @@ msgid " %s - database %s (%f sec.)|%s\n"
msgstr ""
#: plugins/check_pgsql.c:320 plugins/check_time.c:277 plugins/check_time.c:289
#: plugins/check_users.c:228
#: plugins/check_users.c:241
msgid "Critical threshold must be a positive integer"
msgstr ""
#: plugins/check_pgsql.c:326 plugins/check_time.c:258 plugins/check_time.c:282
#: plugins/check_users.c:226
#: plugins/check_users.c:239
msgid "Warning threshold must be a positive integer"
msgstr ""
@ -5513,39 +5513,39 @@ msgstr ""
msgid "http://www.networkupstools.org"
msgstr ""
#: plugins/check_users.c:91
#: plugins/check_users.c:101
#, c-format
msgid "Could not enumerate RD sessions: %d\n"
msgstr ""
#: plugins/check_users.c:146
#: plugins/check_users.c:156
#, c-format
msgid "# users=%d"
msgstr ""
#: plugins/check_users.c:164
#: plugins/check_users.c:177
msgid "Unable to read output"
msgstr ""
#: plugins/check_users.c:166
#: plugins/check_users.c:179
#, c-format
msgid "USERS %s - %d users currently logged in |%s\n"
msgstr ""
#: plugins/check_users.c:241
#: plugins/check_users.c:254
msgid "This plugin checks the number of users currently logged in on the local"
msgstr ""
#: plugins/check_users.c:242
#: plugins/check_users.c:255
msgid ""
"system and generates an error if the number exceeds the thresholds specified."
msgstr ""
#: plugins/check_users.c:252
#: plugins/check_users.c:265
msgid "Set WARNING status if more than INTEGER users are logged in"
msgstr ""
#: plugins/check_users.c:254
#: plugins/check_users.c:267
msgid "Set CRITICAL status if more than INTEGER users are logged in"
msgstr ""