48 lines
988 B
C
48 lines
988 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
#include <sys/wait.h>
|
|
|
|
#define COMMAND_MAX_LENGTH 256
|
|
|
|
int main(int argc, char **argv) {
|
|
int warning_level = 80;
|
|
int critical_level = 90;
|
|
int help_needed = 0;
|
|
int opt;
|
|
char command[COMMAND_MAX_LENGTH];
|
|
|
|
/* Vérification du setuid root */
|
|
if (setuid(0) != 0) {
|
|
perror("setuid root error.\n");
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
/* Analyse des options */
|
|
while ((opt = getopt (argc, argv, "w:c:")) != -1) {
|
|
switch (opt)
|
|
{
|
|
case 'w':
|
|
warning_level = atoi(optarg);
|
|
break;
|
|
|
|
case 'c':
|
|
critical_level = atoi(optarg);
|
|
break;
|
|
|
|
case '?':
|
|
help_needed = 1;
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* Lancement de la commande */
|
|
if (help_needed != 0) {
|
|
return system("/usr/local/sbin/check_pve_mem.pl -h");
|
|
}
|
|
if ( ! snprintf(command, COMMAND_MAX_LENGTH, "/usr/local/sbin/check_pve_mem.pl -w %d -c %d", warning_level, critical_level)) {
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
exit(WEXITSTATUS(system(command)));
|
|
}
|