/****************************************************************************** * * CHECK_ROMFS.C * * Program: Linux plugin for Nagios * License: GPL * Copyright (c) 2009- Victor Ruiz (vruiz@adif.es) * * Description: * * This software checks the LSB of f_flag from struct statvfs to discover * Read_Only Mounted Filesystems. * * License Information: * * 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 2 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, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * $Id: check_romfs.c,v 0.9 2009/04/08 17:39:45 savirziur Exp $ * *****************************************************************************/ #include #include #include #include #include #define MAX(a, b) (((a) > (b)) ? (a) : (b)) #define MAX_PATH 1024 enum nagios_states { OK, WARNING, CRITICAL, UNKNOWN }; int main (int argc, char *argv[]) { struct statvfs buffer; char *output[argc - 1]; int state = OK, i; char line[MAX_PATH]; if ( argc < 2 ) { printf("\n Usage: %s [ path_2 ... ]\n\n\ is the pathname of any file or directory within the mounted file system\n\n\ Device pathnames may yield false read-write mountings: e.g. CD-ROM's\n\n", argv[0]); return (UNKNOWN); } for ( i=1; i < argc; i++ ) { memset(line, '\0', sizeof(line)); if ( -1 == statvfs(argv[i], &buffer) ) { state = MAX(state, WARNING); sprintf(line,"%s %s", argv[i], strerror(errno)); } else { if ( buffer.f_flag & ST_RDONLY ) { state = MAX(state, CRITICAL); sprintf(line,"%s mounted READ_ONLY", argv[i]); } else { sprintf(line,"%s mounted READ_WRITE", argv[i]); } } output[i] = (char *) malloc(sizeof(line)); strcpy(output[i], line); } switch(state){ case OK: printf("OK:"); break; case WARNING: printf("WARNING:");break; case CRITICAL: printf("CRITICAL:");break; } for ( i=1; i < argc; i++ ) { printf(" -- %s ", output[i]); free (output[i]); } putchar('\n'); return state; }