"Fossies" - the Fresh Open Source Software Archive

Member "unix/plugins/pandora_df_free" (15 Sep 2021, 2346 Bytes) of package /linux/misc/pandorafms_agent_unix-7.0NG.757.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl
    2 ###############################################################################
    3 #
    4 # Copyright (c) 2009  Ramon Novoa  <rnovoa@artica.es>
    5 # Copyright (c) 2009  Artica Soluciones Tecnologicas S.L.
    6 #
    7 # pandora_df    Retrieve filesystem disk usage. By default information for all
    8 #       filesystems is returned, but one or more filesystems may be
    9 #       specified as command line parameters.
   10 #
   11 # Sample usage: ./pandora_df tmpfs /dev/sda1
   12 #
   13 # This program is free software; you can redistribute it and/or modify
   14 # it under the terms of the GNU General Public License as published by
   15 # the Free Software Foundation; version 2 of the License.
   16 # 
   17 # This program is distributed in the hope that it will be useful,
   18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20 # GNU General Public License for more details.  
   21 #
   22 ###############################################################################
   23 
   24 use strict;
   25 
   26 # Retrieve information from all filesystems
   27 my $all_filesystems = 0;
   28 
   29 # Check command line parameters
   30 if ($#ARGV < 0) {
   31     $all_filesystems = 1;
   32 }
   33     
   34 # Parse command line parameters
   35 my %filesystems;
   36 foreach my $fs (@ARGV) {
   37     $filesystems{$fs} = '0%';
   38 }
   39 
   40 # Retrieve filesystem information
   41 # -P use the POSIX output format for portability
   42 my @df = `df -P`;
   43 shift (@df);
   44 
   45 # No filesystems? Something went wrong.
   46 if ($#df < 0) {
   47     exit 1;
   48 }
   49 
   50 # Parse filesystem usage
   51 foreach my $row (@df) {
   52     my @columns = split (' ', $row);
   53     exit 1 if ($#columns < 4);
   54     $filesystems{$columns[5]} = $columns[4] if (defined ($filesystems{$columns[5]}) || $all_filesystems == 1);
   55 }
   56 
   57 my $free;
   58 
   59 while (my ($filesystem, $use) = each (%filesystems)) {
   60 
   61     # Remove the trailing %
   62     chop ($use);
   63     $free = 100 - $use;
   64     
   65     # Print module output
   66     print "<module>\n";
   67     print "<name><![CDATA[Disk_" . $filesystem . "]]></name>\n";
   68     print "<type><![CDATA[generic_data]]></type>\n";
   69     print "<data><![CDATA[" . $free . "]]></data>\n";
   70     print "<min_critical><![CDATA[0]]></min_critical>\n";
   71     print "<unit><![CDATA[%]]></unit>\n";
   72     print "<max_critical><![CDATA[5]]></max_critical>\n";
   73     print "<min_warning><![CDATA[5]]></min_warning>\n";
   74     print "<max_warning><![CDATA[10]]></max_warning>\n";
   75     print "<description><![CDATA[% of free space in this volume]]></description>\n";
   76     print "</module>\n";
   77 }
   78 
   79 exit 0;