* Make a script to monitore the file systems informations and put it in "update-motd.d".

This commit is contained in:
gardouille 2015-02-02 14:51:53 +01:00
parent a657aeaf9a
commit 69dcc4fa1c
5 changed files with 75 additions and 0 deletions

View File

@ -12,6 +12,7 @@
* Make a script to monitore the system informations and put it in "update-motd.d".
* Make a script to monitore the user informations and put it in "update-motd.d".
* Make a script to monitore the auth informations and put it in "update-motd.d".
* Make a script to monitore the file systems informations and put it in "update-motd.d".
---------------------------------------

View File

@ -32,6 +32,12 @@ class dynmotd::config {
content => template("${dynmotd::auth_info_script_content}"),
}
->
file { "${dynmotd::update_motd_dir_path}/${dynmotd::fs_info_script_name}":
ensure => present,
mode => 0755,
content => template("${dynmotd::fs_info_script_content}"),
}
->
file { "${dynmotd::update_motd_dir_path}/${dynmotd::service_info_script_name}":
ensure => present,
mode => 0755,

View File

@ -43,6 +43,8 @@ class dynmotd (
$user_info_script_content = $dynmotd::params::user_info_script_content,
$auth_info_script_name = $dynmotd::params::auth_info_script_name,
$auth_info_script_content = $dynmotd::params::auth_info_script_content,
$fs_info_script_name = $dynmotd::params::fs_info_script_name,
$fs_info_script_content = $dynmotd::params::fs_info_script_content,
$service_info_script_name = $dynmotd::params::service_info_script_name,
$service_info_script_content = $dynmotd::params::service_info_script_content,
) inherits dynmotd::params {

View File

@ -14,6 +14,8 @@ class dynmotd::params {
$user_info_script_content = 'dynmotd/motd_user_info.erb'
$auth_info_script_name = '03auth_info'
$auth_info_script_content = 'dynmotd/motd_auth_info.erb'
$fs_info_script_name = '04fs_info'
$fs_info_script_content = 'dynmotd/motd_fs_info.erb'
$service_info_script_name = '06service_info'
$service_info_script_content = 'dynmotd/motd_service_info.erb'

64
templates/motd_fs_info.erb Executable file
View File

@ -0,0 +1,64 @@
#! /usr/bin/env sh
#############################################################################
#
# Usage:
# * Run it as user: <%= scope.lookupvar('dynmotd::dynmotd_bin_path') %>
# * Run it at user login:
# <file bash /etc/profile>
# <%= scope.lookupvar('dynmotd::dynmotd_bin_path') %>
# </file>
# * Or set a cron job with a privileged user (access log files, ...)
# <file bash /etc/cron.d/dynmotd>
# */30 * * * * root rm -f /etc/motd && <%= scope.lookupvar('dynmotd::dynmotd_bin_path') %> > /etc/motd
# </file>
#############################################################################
#### Colors definition
BLACK='\033[30;40m'
RED='\033[0;31m'
REDB='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[34;40m'
MAGENTA='\033[0;35m'
CYAN='\033[36;40m'
WHITE='\033[0;37m'
WHITEB='\033[1;37m'
RESET='\033[0m'
printf '%b' "${MAGENTA}++++++++++++++++++++: ${WHITE}Disk Usage${MAGENTA} :+++++++++++++++++++++${RESET}"
# Root partition
# Replace by rootfs in few kernel version
DISK_USAGE=$(df | grep -m1 "/$" | awk '{print $5}')
printf '%b' "\n${MAGENTA}+ ${WHITEB}/${RESET}\t[ ${DISK_USAGE} ] "
# Other partition
for PART in /boot /home /opt /tmp /usr /var /var/lib/vz; do
# "/...$" : $ to grep only the mount point and not sub-directories (/var: OK; /mnt/temp: nOK)
if (df | grep "${PART}$" > /dev/null); then
DISK_USAGE=$(df | grep "${PART}$" | awk '{print $5}')
printf '%b' "\n${MAGENTA}+ ${WHITEB}${PART}${RESET}\t[ ${DISK_USAGE} ] "
fi
done
### IF ZFS
if [ $(which zpool) ]; then
printf '%b' "${MAGENTA}+++++++++++++++++++ ${WHITEB}ZFS${RESET} ${WHITE}Partitions${MAGENTA} :++++++++++++++++++${RESET}"
NUMBER_PART=$(df -T | grep zfs | wc -l)
LINE=1
while [ "${LINE}" -le "${NUMBER_PART}" ]; do
PART_NAME=$(df -T | grep zfs | sed -n "${LINE},${LINE}p" | awk '{print $1}')
DISK_USAGE=$(df -T | grep zfs | sed -n "${LINE},${LINE}p" | awk '{print $6}')
printf '%b' "\n${MAGENTA}+ ${WHITEB}${PART_NAME}${RESET} [ ${DISK_USAGE} ] "
(( LINE++ ))
done
fi
### FI ZFS
printf '%b' "${RESET}\n"