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

This commit is contained in:
gardouille 2015-02-02 13:42:35 +01:00
parent 557a020967
commit ebc949870c
6 changed files with 58 additions and 4 deletions

View File

@ -8,7 +8,8 @@
##### Changes
* Add new services monitoring (processes and sockets).
* Create the "update-motd.d" to use the dynamic MOTD generation.
* Make a script to manage the services and put it in "update-motd.d".
* Make a script to monitore the services and put it in "update-motd.d".
* Make a script to monitore the system informations and put it in "update-motd.d".
---------------------------------------

View File

@ -14,6 +14,11 @@ class dynmotd::config {
ensure => directory,
}
file { "${dynmotd::update_motd_dir_path}/${dynmotd::system_info_script_name}":
ensure => present,
mode => 0755,
content => template("${dynmotd::system_info_script_content}"),
}
file { "${dynmotd::update_motd_dir_path}/${dynmotd::service_info_script_name}":
ensure => present,
mode => 0755,
@ -21,6 +26,6 @@ class dynmotd::config {
}
File["${dynmotd::update_motd_dir_path}"] -> File["${dynmotd::update_motd_dir_path}/${dynmotd::service_info_script_name}"]
File["${dynmotd::update_motd_dir_path}"] -> File["${dynmotd::update_motd_dir_path}/${dynmotd::system_info_script_name}"] -> File["${dynmotd::update_motd_dir_path}/${dynmotd::service_info_script_name}"]
} # Private class: dynmotd::config

View File

@ -37,6 +37,8 @@
#
class dynmotd (
$update_motd_dir_path = $dynmotd::params::update_motd_dir_path,
$system_info_script_name = $dynmotd::params::system_info_script_name,
$system_info_script_content = $dynmotd::params::system_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

@ -8,11 +8,12 @@ class dynmotd::params {
$update_motd_dir_path = '/etc/update-motd.d'
# DynMotd scripts
$system_info_script_name = '01system_info'
$system_info_script_content = 'dynmotd/motd_system_info.erb'
$service_info_script_name = '06service_info'
$service_info_script_content = 'dynmotd/motd_service_info.erb'
}
}
} # Private class: dynmotd::params

View File

@ -59,7 +59,7 @@ service_info() {
printf '%b' "${MSG}"
}
printf '%b' "\n${MAGENTA}+++++++++++++++++++: ${WHITE}Service Info${MAGENTA} :++++++++++++++++++++${RESET}"
printf '%b' "${MAGENTA}+++++++++++++++++++: ${WHITE}Service Info${MAGENTA} :++++++++++++++++++++${RESET}"
## IF POSTFIX
if [ $(which postfix) ]; then

45
templates/motd_system_info.erb Executable file
View File

@ -0,0 +1,45 @@
#! /usr/bin/env sh
#############################################################################
#
# Usage:
#
#############################################################################
#### 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'
#+++++++++++++++++++: System Data :+++++++++++++++++++
HOSTNAME=$(hostname)
NET_ADDR=$(hostname -I)
KERNEL_VER=$(uname -r)
UPTIME=$(uptime | sed 's/.*up ([^,]*), .*/1/')
CORE_NUMBER=$(grep "model name" /proc/cpuinfo | wc -l)
CPU_MODEL=$(grep -m1 "model name" /proc/cpuinfo | awk -F: '{print $2}')
MEM_FREE=$(grep MemFree /proc/meminfo | awk '{print $2}')
MEM_TOTAL=$(grep MemTotal /proc/meminfo | awk '{print $2}')
SWAP_FREE=$(grep SwapFree /proc/meminfo | awk '{print $2}')
SWAP_TOTAL=$(grep SwapTotal /proc/meminfo | awk '{print $2}')
printf '%b' "${RESET}${MAGENTA}+++++++++++++++++++: ${WHITE}System Data${MAGENTA} :+++++++++++++++++++++${RESET}
${MAGENTA}+ ${WHITE}Hostname\t${MAGENTA}= ${GREEN}${HOSTNAME}
${MAGENTA}+ ${WHITE}Addresses\t${MAGENTA}= ${GREEN}${NET_ADDR}
${MAGENTA}+ ${WHITE}Kernel\t${MAGENTA}= ${GREEN}${KERNEL_VER}
${MAGENTA}+ ${WHITE}Uptime\t${MAGENTA}=${GREEN}${UPTIME}
${MAGENTA}+ ${WHITE}CPU\t\t${MAGENTA}= ${GREEN}${CORE_NUMBER}x${CPU_MODEL}
${MAGENTA}+ ${WHITE}Memory\t${MAGENTA}= ${GREEN}${MEM_FREE}(free)/${MEM_TOTAL}(total) kB
${MAGENTA}+ ${WHITE}Swap\t\t${MAGENTA}= ${GREEN}${SWAP_FREE}(free)/${SWAP_TOTAL}(total) kB${RESET}"
printf '%b' "\n"