Commit aaf9e351 authored by remy's avatar remy
Browse files

saltstack-formula to check disks with smartmontools

parent 0a910a5d
Cette recette permet de verifier les disques a l'aide de `smartmontools`,`smartctl`.
Vous pouvez egalement utiliser des outils Dell, a condition d'avoir deploye les packages Dell avant.
Cette recette peut egalement s'utiliser avec un cron, permettant d'avoir des rapports reguliers.
```bash
salt '$minion' state.sls check_disks
# useful for jsonreader2
salt '$minion' state.sls check_disks.crons
# for dell packages
salt '$minion' state.sls check_disks.megacli
```
test disks:
cmd.run:
- name: '/opt/dell/srvadmin/bin/omreport storage pdisk controller=0 |grep -E "^ID|^Stat"'
- onlyif:
- ls /opt/dell
#!/bin/bash
# sanity check script
#DATE=`date +"%Y%m%d_%H%m%S"`
DATE=`date +"%Y%m%d"`
LOG_FILE="/var/log/disks/"$DATE"_sanity_check.log"
SMARTCTL="/usr/sbin/smartctl"
FILTER='sd|Health'
for disk in `ls -1 /dev/disk/by-id/ |awk 'length($1)==22 && $1 ~ "scsi" {print $1}'`
do
disktype=`readlink /dev/disk/by-id/$disk`
if [[ "$disktype" =~ "sd" ]]; then
flag=""
else
# dm == multipath
flag="-d scsi"
fi
echo /dev/disk/by-id/$disk >> $LOG_FILE
$SMARTCTL $flag -H /dev/disk/by-id/$disk |grep -E "${FILTER}" >> $LOG_FILE
done
for disk in `ls -1 /dev/disk/by-id/ |awk 'length($1)==38 && $1 ~ "scsi" {print $1}'`
do
# DELL BOSS card do not support smart capabilities for now
if [[ ! "$disk" =~ "ATA_DELLBOSS" ]]; then
echo /dev/disk/by-id/$disk >> $LOG_FILE
smartcmd=`$SMARTCTL -H -d megaraid,0 /dev/disk/by-id/$disk`
echo ${smartcmd} |grep -q "SMART Status not supported"
if [ $? -eq 0 ]; then
smartrez=`$SMARTCTL -H /dev/disk/by-id/$disk | grep -E ${FILTER}`
else
smartrez=`$SMARTCTL -H -d megaraid,0 /dev/disk/by-id/$disk |grep -E ${FILTER}`
fi
echo ${smartrez} >> $LOG_FILE
fi
done
disk sanity check:
file.managed:
- name: /usr/local/sbin/disks_sanity_check
- source: salt://disk_sanity_check/check_disks/disks_sanity_check.sh
- user: root
- group: root
- mode: '0755'
/var/log/disks:
file.directory:
- user: root
- group: root
- dir_mode: '0755'
- file_mode: '0644'
include:
{% if grains['manufacturer'] == 'Dell Inc.' %}
- .dellcmd
{% endif %}
- .packages
- .files
unzipping megacli:
cmd.run:
- name: unzip 8-07-14_MegaCLI.zip
alienning megacli:
cmd.run:
- name: "alien --scripts Linux/MegaCli*.rpm"
installing megacli:
cmd.run:
- name: "dpkg -i /root/megacli_8.07.14-2_all.deb"
post-install symlink MegaCli:
file.symlink:
- name: /usr/local/sbin/MegaCli
- target: /opt/MegaRAID/MegaCli/MegaCli64
post-install symlink megacli lower case:
file.symlink:
- name: /usr/local/sbin/megacli
- target: /opt/MegaRAID/MegaCli/MegaCli64
download MegaCli:
file.managed:
- name: /root/8-07-14_MegaCLI.zip
- source: ftp://ngsisem.mbb.univ-montp2.fr/mbbteam/dell/8-07-14_MegaCLI.zip
- source_hash: d9b152ae3dab76a334b9251702dba3311ceed91b58aaf52d916eb4ba1c2ab6e9
include:
- .files
- .packages
- .exec
installing requirements:
pkg.installed:
- pkgs:
- alien
- zip
- unzip
- rpm
Necessite le deploiement de la recette `check_disks` en amont (meme si la machine n'est pas de marque Dell).
S'utilise de la maniere suivante :
```bash
salt '$minion' state.sls check_disks
salt '$minion' state.sls crons.nas.nas_sanity_check
```
Par ailleurs, cette recette n'est pas exclusivement reservee aux NAS et peut etre utilisee avec tout type de machine.
cron disks sanity check:
cron.present:
- name: /usr/local/sbin/disks_sanity_check
- user: root
- special: '@daily'
- onlyif: ls /usr/local/sbin/disks_sanity_check
adding a awk file to transform into json:
file.managed:
- name: /usr/local/bin/filter_disks.awk
- user: root
- group: root
- mode: '0555'
- source: salt://disk_sanity_check/crons/filter_disks.awk
#!/usr/bin/env awk
BEGIN {
print "{";
FS="[/:]";
}
#FNR => compteur par fichier
{
if (NR == FNR) {last++}
else {
if (NR % 2 == 0 && FNR < last) {
ORS=",\n";
} else if (FNR < last) {
ORS=" ";
}
else {
ORS="";
}
if ( $NF ~ "scsi" ) {
print "\t\""$NF"\":";
}
else if ( $0 ~ "Status" ) {
gsub(/ /, "", $0);
print "\""$NF"\"";
}
}
}
END {
print "\n},\n";
#print last;
}
mine_functions:
mine_disks:
- mine_function: cmd.shell
- "awk -f /usr/local/bin/filter_disks.awk /var/log/disks/`date +%Y%m%d`_sanity_check.log /var/log/disks/`date +%Y%m%d`_sanity_check.log"
- allow_tgt: 'G@virtual:physical'
- allow_tgt_type: 'compound'
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment