#!/usr/bin/php
<?php
/*
  vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4:
  Codificación: UTF-8
  +----------------------------------------------------------------------+
  | Issabel version 4.0                                                  |
  | http://www.issabel.org                                               |
  +----------------------------------------------------------------------+
  | Copyright (c) 2006 Palosanto Solutions S. A.                         |
  +----------------------------------------------------------------------+
  | The contents of this file are subject to the General Public License  |
  | (GPL) Version 2 (the "License"); you may not use this file except in |
  | compliance with the License. You may obtain a copy of the License at |
  | http://www.opensource.org/licenses/gpl-license.php                   |
  |                                                                      |
  | Software distributed under the License is distributed on an "AS IS"  |
  | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See  |
  | the License for the specific language governing rights and           |
  | limitations under the License.                                       |
  +----------------------------------------------------------------------+
  | The Initial Developer of the Original Code is PaloSanto Solutions    |
  +----------------------------------------------------------------------+
  $Id: dhcpconfig.php,v 1.1 2007/01/09 23:49:36 alex Exp $
*/

// Lista de directorios a buscar
$listaReporteDir = array(
    'logs'  =>  array(
        'dir'   =>  '/var/log',
        'use'   =>  'N/A',
        'avail' =>  'N/A',
    ),
    'backups'  =>  array(
        'dir'   =>  '/var/www/backup',
        'use'   =>  'N/A',
        'avail' =>  'N/A',
    ),
    'emails'  =>  array(
        'dir'   =>  '/var/spool/imap',
        'use'   =>  'N/A',
        'avail' =>  'N/A',
    ),
    'config'  =>  array(
        'dir'   =>  '/etc',
        'use'   =>  'N/A',
        'avail' =>  'N/A',
    ),
    'voicemails'  =>  array(
        'dir'   =>  '/var/spool/asterisk/voicemail',
        'use'   =>  'N/A',
        'avail' =>  'N/A',
    ),
    'recordings'  =>  array(
        'dir'   =>  '/var/spool/asterisk/monitor',
        'use'   =>  'N/A',
        'avail' =>  'N/A',
    ),
);
foreach (array_keys($listaReporteDir) as $k) {
    if (!is_null($listaReporteDir[$k]['dir'])) {
        $output = NULL; $regs = NULL;
        exec("/usr/bin/du -h {$listaReporteDir[$k]['dir']} 2>/dev/null", $output);
        if (count($output) > 0 && preg_match('/^\s*(\S+)/', $output[count($output) - 1], $regs)) {
            $listaReporteDir[$k]['use'] = $regs[1];
        }
        exec("df -h {$listaReporteDir[$k]['dir']} | grep -v Filesystem | awk '{ print $4 }' 2>/dev/null", $output);
        if (count($output) > 0 && preg_match('/^\s*(\S+)/', $output[count($output) - 1], $regs)) {
            $listaReporteDir[$k]['avail'] = $regs[1];
        }
    }
    
    print "$k ".$listaReporteDir[$k]['use']." ".$listaReporteDir[$k]['avail']."\n";
}
?>
