WikiMiNET

La documentation technique et administrative

Outils pour utilisateurs

Outils du site


wiki:monitoring:userparameters

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
wiki:monitoring:userparameters [2016/07/15 23:07]
tamayo_j [NMap]
wiki:monitoring:userparameters [2018/06/14 11:56]
simtrami [Postgrey SQL]
Ligne 1: Ligne 1:
 +======= Personnalisation Du monitoring à MiNET =======
  
 +===== Apache =====
 +
 +Nous allons accéder à la page de status du serveur apache. Pour celà :
 +
 +  * Créez un Virtual Host monitoring :
 +
 +<code>
 +<Location /server-status>
 +    SetHandler server-status
 +    Allow from 127.0.0.1
 +    Order deny,allow
 +    Deny from all
 +</Location>
 +</code>
 +
 +Les données sont accessibles à cette URL : http://127.0.0.1/server-status
 +
 +Les user parameter ne font que selectionner les données intéressantes :
 +
 +<code bash>
 +UserParameter=apache_custom_stat[*],curl http://127.0.0.1/server-status 2>/dev/null | head -n $1 | tail -n 1 | awk '{print $ $2}'
 +</code>
 +===== NGinx =====
 +
 +Les concept est à peu près le même sur NGinx. Créez un Virtual Host monitoring avec :
 +
 +<code>
 +server {
 +    listen 10061;
 +    location /nginx_status {
 +        stub_status on;
 +        access_log off;
 +        allow 127.0.0.1;
 +        deny all;
 +    }
 +}
 +</code>
 +
 +Puis le tout est accessible à cet URL : http://127.0.0.1:10061/nginx_status
 +
 +Ici aussi le Userparameter ne sert qu'à sélectionner les info qui nous intéressent :
 +
 +<code bash>
 +UserParameter=nginx[*],curl http://127.0.0.1:10061/nginx_status | head -n $1 | tail -n 1 | awk '{print $ $2}'
 +</code>
 +
 +===== MySQL =====
 +
 +Commencez par créer un utilisateur monitoring avec les droits qui vous semblent approprié (pas ceux d'administration).
 +
 +Les valeurs sont obtenue par **mysqladmin**.
 +
 +Voici le Userparameter :
 +
 +<code bash>
 +UserParameter=mysql[*],cat /etc/zabbix/sql.stat| head -n $1 | tail -n 1 | awk '{print $ $2}'
 +</code>
 +
 +===== Postgre SQL =====
 +
 +On peu obtenir directement les informations depuis le client en ligne de commande : **psql**
 +
 +Voici les Userparameters :
 +
 +<code bash>
 +UserParameter=psql.version,psql --version|head -n1
 +UserParameter=psql.server_processes,psql -t -c "select sum(numbackends) from pg_stat_database"
 +UserParameter=psql.tx_commited,psql -t -c "select sum(xact_commit) from pg_stat_database"
 +UserParameter=psql.tx_rolledback,psql -t -c "select sum(xact_rollback) from pg_stat_database"
 +UserParameter=psql.db_size[*],psql -t -c "select pg_database_size('$1')"
 +UserParameter=psql.db_connections[*],psql -t -c "select numbackends from pg_stat_database where datname = '$1'"
 +UserParameter=psql.db_returned[*],psql -t -c "select tup_returned from pg_stat_database where datname = '$1'"
 +UserParameter=psql.db_fetched[*],psql -t -c "select tup_fetched from pg_stat_database where datname = '$1'"
 +UserParameter=psql.db_inserted[*],psql -t -c "select tup_inserted from pg_stat_database where datname = '$1'"
 +UserParameter=psql.db_updated[*],psql -t -c "select tup_updated from pg_stat_database where datname = '$1'"
 +UserParameter=psql.db_deleted[*],psql -t -c "select tup_deleted from pg_stat_database where datname = '$1'"
 +</code>
 +
 +===== NMap =====
 +
 +Le concept est, depuis une machine dédiée, de scanner une fois par jour le réseau MiNET, et de raller si des ports SSH sont ouvert depuis les machines de Prod vers un autre VLAN.
 +
 +Pensez à ajouter les machines dans le 102 qui ont aussi une IP de développement.
 +
 +Un cron éxécute donc nmap depuis l'utilisateur nmap <code> su -c "crontab -l" nmap </code>
 +il serait bon de passer ce script en full awk :
 +
 +<code bash>
 +#!/bin/bash
 +
 +# Romain Cherré (varens) 2017
 +# varens@minet.net
 +# Inspired by the precedent from 
 +# Ignacio Tamayo (localhost) 2016 
 +# tamayo_j@minet.net
 +
 +
 +#Script pour sniffer les ports SSH et TELNET sur plusieurs vlans 
 +#Several files are written with the number or SSH/Telnet server found. Then the Zabbix agent monitores these files and raises alerts
 +#The files _detail.txt are used to identify which host has the ports opened
 +
 +#Check the wiki.minet.net
 +
 +SCRIPTPATH=$(cd -P $(dirname $0); pwd -P)
 +
 +
 +#### Usage ####:
 +##
 +### Add ranges, ... ###
 +# Add port : add port in ports variable and add it behind the list of addresses and range on which you want to test that port
 +# Add vlan : add vlan number VLAN array index and add to it ranges and addresses then ports you want to scan
 +# VLAN syntax : VLAN[<id_vlan>]="<address|range>{1,n} <ports>{1,n} <address|range>{0,n} <ports>{1,n} ..." 
 +#
 +#
 +# Ex VLAN[103]="192.168.103.0/24 23 192.168.103.15 192.168.103.21 192.168.103.18 192.168.103.80 22" will scan 192.168.103.0/24 on port 23 and 192.168.103.15 ... 192.168.103.82 on port 22
 +# and VLAN[2]="157.159.40.0/25 22 23" will scan in vlan 2 on range 157.159.40.0/25 the ports 22 and 23
 +
 +### Reports ###
 +#
 +# The full nmap report for vlan VLAN_ID is found under VLAN_ID_full.txt
 +# The number of host with open port corresponding to protocol P in the vlan VLAN_ID is found in P_VLAN_ID.txt
 +# The addresses of host with an open port corresponding to protocol P in vlan VLAN_ID is found in P_VLAN_ID_detail.txt
 +
 +
 +
 +ports=(22 23)
 +subnets=(2 3 14 102 103)
 +VLAN[2]="157.159.40.0/25 22 23"
 +VLAN[3]="157.159.40.128/26 23"
 +VLAN[14]="192.168.14.0/24 23"
 +VLAN[102]="192.168.102.0/24 23" 
 +VLAN[103]="192.168.103.0/24 23 192.168.103.15 192.168.103.21 192.168.103.18 192.168.103.80 22"
 +
 +
 +for i in ${subnets[@]}; do
 + rm "$i""_full.txt"
 + echo ${VLAN[$i]} | awk '{k=1;
 + while($k!=""){
 + addr=""
 + portList=""
 + while($k~/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/){
 + addr=addr $k " ";
 + k++;
 + }
 + while($k!="" && $k!~/[0-9]+\./){
 + portList=portList $k ",";
 + k++;
 + }
 + system("nmap -sT -PN -p" portList " --append-output -oG " '$SCRIPTPATH/$i'"_full.txt " addr);
 +         }
 +       }'
 +  for j in ${ports[@]};do
 + proto=$(awk '{j=5;while($j!=""){if($j~/'$j'\//){split($j, a ,/\//)}j++}}END{print a[5]}' "$SCRIPTPATH$i""_full.txt" )
 + if [ -n "$proto" ]; then
 + awk '{j=5;while($j!=""){if($j~/'$j'\/open/){print $2};j++}}' "$SCRIPTPATH$i""_full.txt" > "$SCRIPTPATH$proto""_$i""_detail.txt"
 + cat "$SCRIPTPATH$proto""_$i""_detail.txt" | wc -l > "$SCRIPTPATH$proto""_$i"".txt"
 + fi
 + done
 +done
 +
 +
 +</code>
 +
 +Avec zabbix, on ne fait que lire la valeur de ces fichiers. Editez <code>/etc/zabbix/zabbix_agentd.conf</code>
 +
 +<code bash>
 +UserParameter=nmap[*],cat $1
 +</code>
 +
 +Et mettez sur les Triggers Zabbix du host *nmap* un check pour ces items ci
 +
 +===== Firewall =====
 +
 +Nous utilisons netstat -s pour obtenir les stats du firewall.
 +
 +Par ailleurs nous lisons aussi les fichiers indiquant les stats sur la conntrack. Nous comptons aussi le nombre de sockets.  
 +
 +Voici les Userparameters :
 +
 +<code bash>
 +UserParameter=netstat[*],netstat -s | head -n $1 | tail -n 1 | awk '{print $ $2}'
 +UserParameter=socket,netstat -an | grep "tcp\ \|udp\ \|udp6\|tcp6" | wc -l
 +UserParameter=conntrack,cat /proc/sys/net/ipv4/netfilter/ip_conntrack_count
 +UserParameter=conntrack_capacity,cat /proc/sys/net/ipv4/netfilter/ip_conntrack_max
 +</code>
 +
 +===== ZFS =====
 +
 +Le contenu de [[wiki:monitoring:hulk|cette page]] a été utilisé.
 +
 +Voici les user parameters correspondant :
 +
 +<code bash>
 +UserParameter=zstat[*],/etc/zabbix/zstat.sh $1 $2
 +UserParameter=arc[*],/etc/zabbix/arcstat.pl -f arcsz | tail -n 1 | awk '{print $ $1}' | cut -d "G" -f 1
 +UserParameter=l2arc[*],/etc/zabbix/arcstat.pl -f l2size | tail -n 1 | awk '{print $ $1}'| cut -d "G" -f 1
 +UserParameter=memory_rep[*],echo ::memstat | sudo mdb -k | grep $1 | awk '{print $ $2}' | cut -d "%" -f 1
 +UserParameter=zpoolstatus[*],zpool status | grep $1 | wc -l
 +UserParameter=diskperf[*],iostat -xtc | grep $1 | awk '{print $ $2}'
 +UserParameter=raidZfreespac[*],sudo /etc/zabbix/free_space.sh
 +UserParameter=nfs.nfstat[*],nfsstat -s -v 3| head -n $1 | tail -n 1 |  awk '{print $ $2}'
 +UserParameter=nbsocket,netstat -an | wc -l
 +UserParameter=archit[*],/etc/zabbix/arcstat.pl -f read,hits,miss,hit%,l2read,l2hits,l2miss,l2hit%,arcsz,l2size 1 2 | tail -n 1 | awk '{print $ $1}'
 +UserParameter=last_snap_date[*],zfs list -t snapshot | grep '$1/$2@' | tail -n 1 | cut -d "@" -f 2 | cut -d " " -f 1 | cut -c7-12
 +</code>
 +
 +Avec le fichier //zstat.sh//:
 +<code bash>
 +#!/bin/sh
 +
 +case "$2" in
 +        operations_read)
 +                 zpool iostat $1 | tail -n 1 | awk '{print $4}'
 +                 ;;
 +        operations_write)
 +                 zpool iostat $1 | tail -n 1 | awk '{print $5}'
 +                 ;;
 +        bandwidth_read)
 +                 zpool iostat $1 | tail -n 1 | awk '{print $6}' | cut -d "K" -f 1
 +                 ;;
 +        bandwidth_write)
 +                 zpool iostat $1 | tail -n 1 | awk '{print $7}' | cut -d "K" -f 1
 +                 ;;
 +        latency_read)
 +#                 zpool iostat $1 | tail -n 1 | awk '{print $8}'
 +                 iostat | tail -n 1 | awk '{print $5}'
 +                 ;;
 +        latency_write)
 +                 zpool iostat $1 | tail -n 1 | awk '{print $8}'
 +                 ;;
 +        *)
 +                exit 1
 +                ;;
 +
 +esac
 +
 +exit 0
 +</code>
 +
 +De plus, voici les modifications à faire dans ''/etc/sudoers'':
 +
 +<code bash>
 +Cmnd_Alias ZABBIX_PROGRAMMS = /root/arcstat.pl, /usr/bin/mdb, /usr/bin/bc, /sbin/zfs, /usr/sbin/zfs, /usr/sbin/swap, /bin/cat, /etc/zabbix/free_space.sh
 +
 +zabbix ALL=(ALL) NOPASSWD: ZABBIX_PROGRAMMS
 +</code>
 +
 +===== Machines physiques =====
 +
 +Cette [[wiki:monitoring:machine_phy|page]] présente comment installer les outils dont nous allons nous servir.
 +
 +Pour ce qui est du monitoring NFS, nous utilisons ''nfsstat -c''.
 +
 +Par ailleurs nous comptons le nombre de socket retournés par ''netstat -an''
 +
 +Voici les Userparameters :
 +
 +<code bash>
 +UserParameter=sensors.temp.ambient,sudo ipmitool sdr type 'Temperature' |grep Ambient |grep 7.1 |sed -e 's/.*7.1 | \([0-9]\+\).*/\1/'
 +UserParameter=sensors.temp.ram[*],sensors | grep DIMM | tail -n 1 | cut -d '+' -f 2 | awk 'split($ \$1,x,\"°\") { print x[1] }'
 +UserParameter=nfsstat[*],nfsstat -c | head -n \$1 | tail -n 1 |  awk '{print $ \$2}'
 +UserParameter=ioping[*],sudo ioping -c 200 \$1 -i 0.001 | tail -n 1 | cut -d \"=\" -f 2 | cut -d \"/\" -f 3
 +UserParameter=nbsocket,netstat -an | wc -l
 +</code>
 +
 +===== TV =====
 +
 +Nous utilisons un script qui compte le nombre de processus de mumudvb, et qui relance les tunners qui sont éteint. Rien de bien plus compliqué.
 +
 +Le script se trouve ici : ''/etc/zabbix/up_tunner.sh'' et appartient à root.
wiki/monitoring/userparameters.txt · Dernière modification: 2020/06/27 18:16 (modification externe)