Start Stop Zabbix services

ps auxww |grep -v grep | grep zabbix_agentd

cd /etc/init.d/

Zabbix agent

vi zabbix_agent_start.sh
su -l zabbix -c /usr/sbin/zabbix_agentd start

chmod 755 zabbix_agent_start.sh

vi zabbix_agent_stop.sh
ps -ef | grep zabbix_agentd | grep -v grep | awk ‘{print $2}’ | xargs kill -9

chmod 755 zabbix_agent_stop.sh

Put in /etc/rc3.d and /etc/rc5.d

cd /etc/rc3.d/
cd /etc/rc5.d/

ln -s ../init.d/zabbix_agent_stop.sh K20zabbix-agent
ln -s ../init.d/zabbix_agent_start.sh S20zabbix-agent

Zabbix serveur (sur vmoni.ft.grp)

vi zabbix_server_start.sh
su -l zabbix -c /usr/local/sbin/zabbix_server

chmod 755 zabbix_server_start.sh

vi zabbix_server_stop.sh
ps -ef | grep zabbix_server | grep -v grep | awk ‘{print $2}’ | xargs kill -9

chmod 755 zabbix_server_stop.sh

Put in /etc/rc3.d and /etc/rc5.d

cd /etc/rc3.d/
cd /etc/rc5.d/

ln -s ../init.d/zabbix_server_stop.sh K20zabbix-server
ln -s ../init.d/zabbix_server_start.sh S20zabbix-server

Sonde temps de reponse page web

Avec proxy

zab_web_avec.sh

#!/bin/bash
export http_proxy=’gateway.zscaler.net:80′
cd /tmp
d1=`date + »%S.%N »`
wget -q –proxy=on –dns-cache=off http://www.citrix.com
d2=`date + »%S.%N »`
rm /tmp/index.html
echo « scale=2; $d2-$d1 » | bc

Sans proxy

zab_web_sans.sh

#!/bin/bash
cd /tmp
d1=`date + »%S.%N »`
wget -q –proxy=off –dns-cache=off http://www.citrix.com
d2=`date + »%S.%N »`
rm /tmp/index.html
echo « scale=2; $d2-$d1 » | bc

Redémarrage auto des services windows avec Zabbix

Cette procédure permet de redémarrer automatiquement les services windows qui sont « STOPPED » alors qu’ils sont en démarrage automatique, devraient donc être « STARTED ».

1- Sur le serveur cible : Se connecter avec le compte Dcxservice
Copier le fichier C:\Batchs\Start_service_auto.bat (voir en fin d’article) de PSERV dans C:\Batchs
Creer le dossier c:\temp

2- Appliquer le template Tmp_Service_Auto_Restart sur le serveur

3- Facultatif : Modifier (supprimer) les services à exclure sur l’item (serveur cible) .

Liste des serveurs où cette fonctionnalité est implanté.

PSERV
PWEB
VTREND
PDTB1
VWCCO15P
VMEC

ATTENTION :

Le fichier de zabbix_agentd.conf de l’agent Zabbix (sur le serveur cible) doit contenir la ligne :
EnableRemoteCommands=1

———————————————————————————————————————–

C:\Batchs\Start_service_auto.bat

@echo off
cls
:: EF le 16/05/2012
:: MV le 17/01/2017 ajout du check for permissions, windows 2012 r2

setlocal enableDelayedExpansion

:: BatchGotAdmin
:————————————-
REM –> Check for permissions
>nul 2>&1 « %SYSTEMROOT%\system32\cacls.exe » « %SYSTEMROOT%\system32\config\system »

REM –> If error flag set, we do not have admin.
if ‘%errorlevel%’ NEQ ‘0’ (
echo Requesting administrative privileges…
goto UACPrompt
) else ( goto gotAdmin )

:UACPrompt
echo Set UAC = CreateObject^(« Shell.Application »^) > « %temp%\getadmin.vbs »
echo UAC.ShellExecute « %~s0 », «  », «  », « runas », 1 >> « %temp%\getadmin.vbs »

« %temp%\getadmin.vbs »
exit /B

:gotAdmin
if exist « %temp%\getadmin.vbs » ( del « %temp%\getadmin.vbs » )
pushd « %CD% »
CD /D « %~dp0″
:————————————–

set fic_log=c:\temp\service_to_restart.log
set fic_temp=c:\temp\service_to_restart.txt
set fic_start=c:\temp\service_to_start.txt
set fic_bat=c:\temp\service_to_start.bat
del /F %fic_log%
del /F %fic_temp%
del /F %fic_start%
del /F %fic_bat%

TIMEOUT /T 3 /NOBREAK 1>nul

TYPE NUL > %fic_start%
TYPE NUL > %fic_bat%

wmic service where (state= »stopped » and startmode= »Auto ») get name>%fic_temp%

for /f « delims= skip=1 » %%i in (‘type %fic_temp%’) do (
set w_serv=%%i
echo net start %%i>> %fic_start%
)

TIMEOUT /T 3 /NOBREAK 1>nul

for /f « tokens=1,2,3* delims=  » %%i in (%fic_start%) do (
set wstr=%%i %%j
set wser=%%k %%l
for /l %%a in (11,1,100) do if « !wser:~-1! »== »  » set wser=!wser:~0,-1!
set w_ligne=!wstr! »!wser! »
echo !w_ligne!
echo !w_ligne!>>%fic_bat%
echo TIMEOUT /T 5 /NOBREAK >> %fic_bat%
)

%fic_bat% > %fic_log%

Install Zabbix Agent sur Windows

Récupérer l’agent sur PFILE :

\\PFILE\Distrib\Zabbix Agent\zabbix_agents_1.8.10.win

copier le dossier dans :

L:\Soft\

Le fichier L:\Soft\zabbix_agents_1.8.10.win\zabbix_agentd.conf contient

Server=vmoni.ft.grp
EnableRemoteCommands=1
DebugLevel=2
LogFile= L:\Soft\zabbix_agents_1.8.10.win\logs\zabbix_agentd.log

———————————————————————————————————————-

Désinstallationde l’agent attention vérifier les chemins dans les propriétés du service

Fenêtre de cmd:

64 bits

C:\Users\adm_1504>L:\Soft\zabbix_agents_1.8.10.win\win64\zabbix_agentd.exe --uninstall
 zabbix_agentd.exe [4344]: Service "Zabbix Agent" uninstalled successfully
 zabbix_agentd.exe [4344]: Event source "Zabbix Agent" uninstalled successfully.

32 bits

C:\Users\adm_1504>L:\Soft\zabbix_agents_1.8.10.win\win32 \zabbix_agentd.exe --uninstall
 zabbix_agentd.exe [4344]: Service "Zabbix Agent" uninstalled successfully
 zabbix_agentd.exe [4344]: Event source "Zabbix Agent" uninstalled successfully.

———————————————————————————————————————

Installation de l’agent

Fenêtre de cmd en Administrateur:

change user /install

64 bits

C:\Users\adm_1504>L:\Soft\zabbix_agents_1.8.10.win\win64\zabbix_agentd.exe --config L:\Soft\zabbix_agents_1.8.10.win\zabbix_agentd.conf --install
 zabbix_agentd.exe [4704]: service [Zabbix Agent] installed successfully
 zabbix_agentd.exe [4704]: event source [Zabbix Agent] installed successfully

32 bits

C:\Users\adm_1504>L:\Soft\zabbix_agents_1.8.10.win\win32\zabbix_agentd.exe --config L:\Soft\zabbix_agents_1.8.10.win\zabbix_agentd.conf --install
zabbix_agentd.exe [3676]: service [Zabbix Agent] installed successfully
 zabbix_agentd.exe [3676]: event source [Zabbix Agent] installed successfully

Démarrer le service en tant que DcXservice@ft.grp : Dc…..#7….

change user /execute

———————————————————————————————————-

Tester si l’agent fonctionne

Se connecter root sur vmoni il doit retourner la version exemple 1.8.10 pour le serveur vadmin.ft.grp

root@vmoni:~# zabbix_get -p 10050 -k agent.version -s vadmin.fr.grp
1.8.10

Install zabbix agent Linux UBUNTU 1.8

alias ll=’ls -ltra’

Installer le module de Compatibilité 64 bits vs 32 bits. si besoin. apt-get install ia32-libs

if necessary. apt-get install ia32-libs

cat /etc/passwd

adduser zabbix

passwd zabbixadm

addgroup zabbix admin

Si addgroup: The group `admin’ does not exist. le groupe n’esiste pas faire groupadd admin

su – zabbix

cd /home/zabbix

download agent and server components, unpack:

 

scp zabbix@vlecm04p:zabbix-1.8.tar.gz .
tar zvpxf zabbix-1.8.tar.gz

——–

 

scp zabbix@vlecm04p:zabbix_agents_1.8.linux2_6.i386.tar.gz .
tar zvpxf zabbix_agents_1.8.linux2_6.i386.tar.gz

exit (pour revenir sous le compte root)

Copy agent files and create needed directories:

cd /home/zabbix/zabbix-1.8/
mkdir /etc/zabbix mkdir /var/log/zabbix
chown -R zabbix.zabbix /etc/zabbix/
chown -R zabbix.zabbix /var/log/zabbix
cp /home/zabbix/zabbix-1.8/misc/conf/zabbix_agent* /etc/zabbix/
cp /home/zabbix/zabbix-1.8/bin/zabbix_get /usr/bin/
cp /home/zabbix/zabbix-1.8/bin/zabbix_sender /usr/bin/
cp /home/zabbix/zabbix-1.8/sbin/zabbix_agent /usr/sbin/
cp /home/zabbix/zabbix-1.8/sbin/zabbix_agentd /usr/sbin/

Edit zabbix agent configuration:

vi /etc/zabbix/zabbix_agentd.conf

#make sure server ip is correct: 
LogFile=/exploit/logs/zabbix_agentd.log
LogFileSize=1
DebugLevel=3
Server=vmoni.ft.grp
Hostname=nom_du_client
DisableActive=1
UserParameter=system.topcpu[*],/exploit/scripts/topcpu.sh $1
UserParameter=zab_mem_free,/exploit/scripts/zab_mem_free.sh
UserParameter=zab_proc_mem[*],/exploit/scripts/zab_proc_mem.sh $1
UserParameter=zab_proc_cpu[*],/exploit/scripts/zab_proc_cpu.sh $1

Récupration des scripts :

scp root@vsch1.ft.grp:/exploit/scripts/zab_m*.sh .
scp root@vsch1.ft.grp:/exploit/scripts/zab_p*.sh .
scp root@vsch1.ft.grp:/exploit/scripts/topcpu.sh .

Edit Services file:

cat /etc/services|grep zabbix

vi /etc/services

#Add the following rules at the end: 
zabbix_agent 10050/tcp # Zabbix ports 
zabbix_trap 10051/tcp # Zabbix ports

Copy the init.d scripts:

cp /home/zabbix/zabbix-1.8/misc/init.d/debian/zabbix-agent /etc/init.d

Edit the script files :

vi /etc/init.d/zabbix-agent

#Change:
 #DAEMON=/home/zabbix/bin/${NAME}
 DAEMON=/usr/sbin/${NAME}

Set the correct permissions and set zabbix to start automatically:

chmod 755 /etc/init.d/zabbix-agent
update-rc.d zabbix-agent defaults

Stop / Start the agent:

cd /etc/init.d

vi zabbix_agent_start.sh

su -l zabbix -c /usr/sbin/zabbix_agentd start

vi zabbix_agent_stop.sh

ps -ef | grep zabbix_agentd | grep -v grep | awk ‘{print $2}’ | xargs kill -9

chmod 755 zabbix_agent_st*.sh

cd /etc/rc3.d/
ln -s ../init.d/zabbix_agent_stop.sh K20zabbix_agentd
ln -s ../init.d/zabbix_agent_start.sh S20zabbix_agentd

cd /etc/rc5.d/
ln -s ../init.d/zabbix_agent_stop.sh K20zabbix_agentd
ln -s ../init.d/zabbix_agent_start.sh S20zabbix_agentd

To stop zabbix agent

./K20zabbix_agentd

To start zabbix agent

./S20zabbix_agentd

Check if the Agent is running:
ps -aux | grep -v grep | grep zabbix_agentd
zabbix 10302 0.0 0.0 3368 556 ? SN 14:32 0:00 /usr/sbin/zabbix_agentd
zabbix 10303 0.4 0.0 3368 796 ? SN 14:32 0:00 /usr/sbin/zabbix_agentd
zabbix 10304 0.0 0.0 3368 440 ? SN 14:32 0:00 /usr/sbin/zabbix_agentd
zabbix 10305 0.0 0.0 3368 440 ? SN 14:32 0:00 /usr/sbin/zabbix_agentd
zabbix 10306 0.0 0.0 3368 440 ? SN 14:32 0:00 /usr/sbin/zabbix_agentd
zabbix 10307 0.0 0.0 3404 840 ? SN 14:32 0:00 /usr/sbin/zabbix_agentd
zabbix 10323 0.0 0.0 7528 892 pts/1 R+ 14:32 0:00 grep zabbix_agent

Test the proper operation of the agent

Connect on vmoni with root account

cd /usr/local/bin

root@vmoni:~# zabbix_get -p 10050 -k agent.version -s servername

1.8

Must return the version of the zabbix agent.

Install zabbix agent Linux REDHAT

alias ll=’ls -ltra’

download agent and server components, unpack and compiles :ll /et

[ora102@hyde ERPMIG agent]$ cd /data/zabbix/agent
[ora102@hyde ERPMIG agent]$ gunzip zabbix-1.8.5.tar.gz
[ora102@hyde ERPMIG agent]$ tar -xvf zabbix-1.8.5.tar
[root@hyde ~]# sudo groupadd -g 9000 zabbix
[root@hyde ~]# sudo adduser -m -d /home/zabbix -g 9000 zabbix
[root@hyde ~]# sudo passwd zabbix
zabbix#123

[root@hyde ~]# cd /data/zabbix/agent/zabbix-1.8.5 
[root@hyde zabbix-1.8.5]# ./configure --enable-agent 

config.status: creating src/zabbix_server/proxypoller/Makefile config.status: creating src/zabbix_server/selfmon/Makefile config.status: creating src/zabbix_proxy/Makefile config.status: creating src/zabbix_proxy/heart/Makefile config.status: creating src/zabbix_proxy/housekeeper/Makefile config.status: creating src/zabbix_proxy/proxyconfig/Makefile config.status: creating src/zabbix_proxy/datasender/Makefile config.status: creating upgrades/Makefile config.status: creating man/Makefile config.status: creating include/config.h config.status: executing depfiles commands Configuration: Detected OS: linux-gnu Install path: /usr/local Compilation arch: linux Compiler: gcc Compiler flags: -g -O2 Enable server: no Enable proxy: no Enable agent: yes Agent details: Linker flags: -rdynamic Libraries: -lm -lresolv LDAP support: no IPv6 support: no *********************************************************** * Now run 'make install' * * * * Thank you for using Zabbix! * * * ***********************************************************

[root@hyde zabbix-1.8.5]# make install

Set /etc/services and agent.conf

[root@hyde zabbix-1.8.5]# vim /etc/services

#------------------------------------- # Srvices Zabbix #-------------------------- 

zabbix_agent 10050/tcp 
zabbix_trap 10051/tcp

[root@hyde sbin]# cd /usr/local/sbin
[root@hyde sbin]# ll
total 1084
-rwxr-xr-x 1 root root 492955 mai 23 14:51 zabbix_agent
-rwxr-xr-x 1 root root 594638 mai 23 14:51 zabbix_agentd

[root@hyde etc]# cd /etc
[root@hyde etc]# mkdir zabbix
[root@hyde etc]# cp /data/zabbix/agent/zabbix-1.8.5/misc/conf/zabbix_agent.conf /etc/zabbix/
[root@hyde sbin]# cp /data/zabbix/agent/zabbix-1.8.5/misc/conf/zabbix_agentd.conf /etc/zabbix/

[root@hyde sbin]# vim /etc/zabbix/zabbix_agentd.conf

# 
# Mandatory: no 
# Default: 
# LogRemoteCommands=0 
##### Passive checks related ### 
Option: Server 
# List of comma delimited IP addresses (or hostnames) of Zabbix servers. 
# No spaces allowed. First entry is used for receiving list of and sending active checks. 
# If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally. 
# 
# Mandatory: yes 
# Default: 
# Server= Server=vmoni.ft.grp ### 
Option: Hostname 
# Unique, case sensitive hostname. 
# Required for active checks and must match hostname as configured on the server. 
# System hostname is used if undefined. 
# 
# Default: 
# Hostname=system.hostname Hostname=Hyde 
### Option: ListenPort 
# Agent will listen on this port for connections from the server. # 
# Mandatory: no 
# Range: 1024-32767 
# Default: 
ListenPort=10050 
### Option: ListenIP 
# List of comma delimited IP addresses that the agent should listen on. 
# 
# 
Mandatory: no 
# 
Default: ListenIP=10.1.1.79 
### 
Option: DisablePassive

Copy and Modify zabbix_agentd_ctl file :

[root@hyde redhat]# cd /data/zabbix/agent/zabbix-1.8.5/misc/init.d/redhat/
[root@hyde redhat]# ll
total 24
drwxr-xr-x 2 zabbix zabbix 4096 avr 15 21:20 8.0
-rwxr-xr-x 1 zabbix zabbix 3214 avr 15 21:17 zabbix_agentd_ctl
-rwxr-xr-x 1 zabbix zabbix 3198 avr 15 21:17 zabbix_server_ctl
[root@hyde redhat]# cp zabbix_agentd_ctl /etc/init.d/

[root@hyde redhat]# cd /etc/init.d/
[root@hyde redhat]# vim zabbix_agentd_ctl

# base zabbix dir 
#BASEDIR=/opt/zabbix 
BASEDIR=/usr/local/

STOP / START Agent

[root@hyde init.d]# ./zabbix_agentd_ctl stop
./zabbix_agentd_ctl stop: zabbix_agentd process(es) stopped
[root@hyde init.d]# ps aux |grep zabbix_agent
root 12057 0.0 0.0 52148 768 pts/3 S+ 11:08 0:00 grep zabbix_agent
[root@hyde init.d]# ./zabbix_agentd_ctl start
./zabbix_agentd_ctl start: zabbix_agentd started
[root@hyde init.d]# ps aux |grep zabbix_agent
zabbix 12064 0.0 0.0 7188 788 ? SN 11:08 0:00 /usr/local/sbin/zabbix_agentd
zabbix 12065 0.0 0.0 7188 1000 ? SN 11:08 0:00 /usr/local/sbin/zabbix_agentd
zabbix 12066 0.0 0.0 7188 788 ? SN 11:08 0:00 /usr/local/sbin/zabbix_agentd
zabbix 12067 0.0 0.0 7188 788 ? SN 11:08 0:00 /usr/local/sbin/zabbix_agentd
zabbix 12068 0.0 0.0 7188 788 ? SN 11:08 0:00 /usr/local/sbin/zabbix_agentd
zabbix 12069 0.0 0.0 8232 912 ? SN 11:08 0:00 /usr/local/sbin/zabbix_agentd
root 12089 0.0 0.0 52148 768 pts/3 S+ 11:08 0:00 grep zabbix_agent
[root@hyde init.d]#

cd /etc/rc3.d/
ln -s ../init.d/zabbix_agent_stop.sh K20zabbix-agent
ln -s ../init.d/zabbix_agent_start.sh S20zabbix-agent

Test the proper operation of the agent

Connect on vmoni with root account

cd /usr/local/bin

root@vmoni:~# zabbix_get -p 10050 -k agent.version -s servername

1.8.5

Must return the version of the zabbix agent.


NLE notes, test oracle probes

[zabbix@hyde ERPTEST sbin]$ ./zabbix_agent -c /etc/zabbix/zabbix_agentd.conf -t ora-check-instance-erptest

root@vmoni:/etc/zabbix# zabbix_get -s hyde.faiveleytransport.local -p 10050 -k ora-check-instance-erptest
ZBX_NOTSUPPORTED

root@vmoni:/etc/zabbix# zabbix_get -s 127.0.0.1 -p 10050 -k agent.version
1.8.5
root@vmoni:/etc/zabbix# zabbix_get -s 127.0.0.1 -p 10050 -k testnico
3

3.7 Zabbix Get (UNIX)
Zabbix UNIX Get est un processus qui communique avec l’agent ZABBIX et récupère les informations nécessaires.
Cet utilitaire est généralement utilisé pour résoudre les problèmes des agents ZABBIX.
Zabbix Get peut être démarré en utilisant:
shell> cd bin
shell> ./zabbix_get -s127.0.0.1 -p10050 -k »system.cpu.load[all,avg1] »
Zabbix Get accepte les paramètres en ligne de commandes suivants:
-p –port Spécifie le port de l’agent qui fonctionne sur l’hôte. La valeur par défaut est 10050.
-s -host Spécifie le nom machine ou l’adresse IP de l’hôte.
-I –source-address Spécifie l’adresse IP source
-k -key Spécifie le nom de la métrique (clé) que nous voulons récupérer.
-h –help Affiche cette aide.
-v –version Affiche la version.
Pour afficher cette aide:
shell> zabbix_get -h

Vérification d’un item

root@vmoni:~# zabbix_get -s hyde.faiveleytransport.local -p 10050 -k oracle[latchfree,erptest,gpbatch,hornet]
658

root@vmoni:~# zabbix_get -s hyde.faiveleytransport.local -p 10050 -k oracle[version,erptest,gpbatch,hornet]
Oracle Database 10g Release 10.2.0.4.0 – 64bit Production

Install zabbix agent Linux OEL5

alias ll=’ls -ltra’

Example : Install zabbix agent on vdtb4.

Create zabbix user

cat /etc/passwd

adduser zabbix

pwd : zabbixadm

addgroup zabbix admin

su – zabbix

cd /home/zabbix

Download agent and server components, unpack:

Distrib Zabbix : www.zabbix.com/download2.php

wget http://downloads.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/1.8/zabbix-1.8.tar.gz
tar zxvpf zabbix-1.8.tar.gz
wget http://www.zabbix.com/downloads/1.8.5/zabbix_agents_1.8.5.linux2_6.i386.tar.gz
tar zxvf zabbix_agents_1.8.5.linux2_6.i386.tar.gz

Copy agent files and create needed directories:

cd /home/zabbix/zabbix-1.8/
mkdir /etc/zabbix
mkdir /var/log/zabbix
chown -R zabbix.zabbix /etc/zabbix/
chown -R zabbix.zabbix /var/log/zabbix
cp /home/zabbix/zabbix-1.8.5/misc/conf/zabbix_agent* /etc/zabbix/
cp /home/zabbix/bin/zabbix_get /usr/bin/
cp /home/zabbix/bin/zabbix_sender /usr/bin/
cp /home/zabbix/sbin/zabbix_agent /usr/sbin/
cp /home/zabbix/sbin/zabbix_agentd /usr/sbin/

Edit zabbix agent configuration:

vim /etc/zabbix/zabbix_agentd.conf

Change :
DebugLevel=1

Server=vmoni.ft.grp

Hostname=vdtb4.ft.grp (Nom du client)

ListenPort=10050

ListenIP=130.117.62.228 (Ip du client)

Edit Services file:

cat /etc/services | grep 10050
cat /etc/services | grep 10051

vim /etc/services

#Add the following rules at the end:
zabbix_agent 10050/tcp # Zabbix ports
zabbix_trap 10051/tcp # Zabbix ports

Copy the init.d scripts:

cp /home/zabbix/zabbix-1.8/misc/init.d/redhat/zabbix_agentd_ctl /etc/init.d

#Edit the script files:
vim /etc/init.d/zabbix_agentd_ctl

#Change:
#BASEDIR=/opt/zabbix
BASEDIR=/usr

#ZABBIX_AGENTD=$BASEDIR/bin/zabbix_agentd
ZABBIX_AGENTD=$BASEDIR/sbin/zabbix_agentd

Set the correct rights and set zabbix to start automatically:

ll /etc/init.d/zabbix_agentd_ctl
chmod 755 /etc/init.d/zabbix_agentd_ctl
update-rc.d zabbix_agentd_ctl defaults

#Start the agent:
./zabbix_agentd_ctl start

#Check if the Agent is running:
ps aux | grep -v grep | grep zabbix_agentd

zabbix 3479 0.0 0.0 2748 536 ? SN 10:21 0:00 /usr/sbin/zabbix_agentd
zabbix 3480 0.0 0.0 2748 764 ? SN 10:21 0:00 /usr/sbin/zabbix_agentd
zabbix 3481 0.0 0.0 2748 420 ? SN 10:21 0:00 /usr/sbin/zabbix_agentd
zabbix 3482 0.0 0.0 2748 420 ? SN 10:21 0:00 /usr/sbin/zabbix_agentd
zabbix 3483 0.0 0.0 2772 768 ? SN 10:21 0:00 /usr/sbin/zabbix_agentd
zabbix 3484 0.0 0.0 2780 772 ? SN 10:21 0:00 /usr/sbin/zabbix_agentd

Test the proper operation of the agent.

Connect on vmoni with root account.

cd /usr/local/bin

root@vmoni:~# zabbix_get -p 10050 -k agent.version -s servername

1.8.5

Must return the version of the zabbix agent.

Test IF … ELSE

Test ERRORLEVEL avec les enableDelayedExpansion

IF !ERRORLEVEL!==0 (
echo condition vrai
) ELSE ( — facultative
echo condition fausse — facultative
)
del /F /Q c:\test_proc.tmp
TIMEOUT /T 2 /NOBREAK
echo *******************************************
)

Lance l’exécution conditionnelle dans un programme de commandes.

IF [NOT] ERRORLEVEL nombre commande
IF [NOT] chaîne1==chaîne2 commande
IF [NOT] EXIST nom_de_fichier commande

NOT : Indique que Windows 2000 n’effectue la commande que si la condition est fausse.

ERRORLEVEL nombre : Condition vraie si le dernier programme exécuté a retourné un code sortie supérieur/égal au nombre donné.

commande : Spécifie la commande à exécuter si la condition est satisfaite.

chaîne1==chaîne2 : Condition vraie si les chaînes spécifiées sont identiques.

EXIST nom_de_fichier : Condition vraie si le nom de fichier donné existe.

 

commande : Spécifie la commande à exécuter si la condition est vérifiée. Commande peut être suivi de la commande ELSE qui exécutera la commande située après le mot-clé ELSE si la condition est fausse (FALSE)

La clause ELSE doit être sur la même ligne que la commande suivant IF.
Par exemple:

IF EXIST nomfichier. (
del nomfichier.
) ELSE (
echo nomfichier. introuvable.
)

L’exemple suivant NE marche PAS car la commande del doit être terminée par une nouvelle ligne.

IF EXIST nomfichier. del nomfichier. ELSE echo nomfichier. introuvable

L’exemple suivant NE marche PAS non plus, car la commande ELSE doit être sur la même ligne que la fin de la commande IF :

IF EXIST nomfichier. del nomfichier.
ELSE echo nomfichier. introuvable

Enfin, l’exemple suivant marche si vous l’écrivez sur une seule ligne :

IF EXIST nomfichier. (del nomfichier.) ELSE echo nomfichier. introuvable

Si les extensions de commandes sont activées, IF est modifié comme suit :
IF [/I] Chaîne1 op-de-comp Chaîne2 commande
IF CMDEXTVERSION nombre commande
IF DEFINED variable commande

op-de-comp peut être :

EQU – égal à
NEQ – différent de
LSS – inférieur à
LEQ – inférieur ou égal à
GTR – supérieur à
GEQ – supérieur ou égal à

et le commutateur /I, s’il est spécifié, demande d’ignorer la casse dans la comparaison des chaînes. Le commutateur /I peut également être utilisé pour la forme Chaîne1==Chaîne2 de IF. Ces comparaisons sont génériques : si les chaînes Chaîne1 et Chaîne2 sont toutes deux faites uniquement de chiffres, alors elles sont converties en nombres, et une comparaison numérique est alors effectuée.

La condition CMDEXTVERSION marche comme ERRORLEVEL, sauf qu’elle compare à un numéro de version interne associé aux extensions de commandes. La première version des extensions est 1. Ce numéro sera incrémenté de un à chaque amélioration significative. La condition CMDEXTVERSION n’est jamais vraie lorsque les extensions de commandes sont désactivées.

La condition DEFINED fonctionne comme EXISTS, sauf qu’elle prend un nom de variable d’environnement et renvoie vrai si la variable d’environnement est définie.

%ERRORLEVEL% sera une représentation sous forme de chaîne de la valeur en cours de ERRORLEVEL, pourvu qu’il n’existe pas déjà de variable d’environnement portant le nom ERRORLEVEL, auquel cas ce serait la valeur de cette dernière que vous obtiendriez. En utilisant cela et les comparateurs numériques ci-dessous, vous pouvez faire :

goto answer%ERRORLEVEL%

:answer0

echo Le programme a retourné le code 0

:answer1

echo Le programme a retourné le code 1

vous pouvez aussi faire, en utilisant les comparaisons numériques ci-dessus :

IF %ERRORLEVEL% LEQ 1 goto okay

%CMDCMDLINE% sera la ligne de commande originale passée à CMD.EXE avant tout traitement par CMD.EXE, pourvu qu’il n’existe pas déjà de variable d’environnement portant le nom CMDCMDLINE, auquel cas ce serait la valeur de cette dernière que vous obtiendriez.

%CMDEXTVERSION% sera une chaîne représentant la valeur actuelle de

CMDEXTVERSION, tant qu’il n’existe pas déjà de variable d’environnement appelée CMDEXTVERSION, dans quel cas vous obtiendrez sa valeur à la place.

Task : Processus windows

Afficher l’état d’un processus

tasklist /FI « imagename eq putty.exe »

Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
putty.exe 10080 RDP-Tcp#1 3 10076 K
putty.exe 2520 RDP-Tcp#3 4 9012 K
putty.exe 10072 RDP-Tcp#1 3 11400 K
putty.exe 9168 RDP-Tcp#3 4 8384 K
putty.exe 12776 RDP-Tcp#3 4 9152 K
putty.exe 14084 RDP-Tcp#3 4 9408 K
putty.exe 17864 RDP-Tcp#3 4 9368 K

Tuer les processus

TASKKILL /F /IM putty.exe /T

sleep, wait, timeout

Linux : sleep 60

Attend 60 secondes

time /T

ping 0.0.0.0 -w 1000 -n 60 > nul

time /T

-w en millisecondes (1000 = 1s)
-n nombre de ping (60 pour 60 secondes=1minute)
>nul pour ne rien afficher

TIMEOUT /Tdélai_d’attente /NOBREAK

Description :
Cet utilitaire accepte un paramètre de délai d’attente qui définit la période de temps d’attente (en secondes) ou jusqu’à ce qu’une frappe de touche se produise. Il accepte également un paramètre pour ignorer l’utilisation d’une touche.

Liste de paramètres :
/T délai_maximal Spécifie le nombre de secondes d’attente.
La plage valide est comprise entre -1 et 99999 secondes.

/NOBREAK Ignorer l’utilisation des touches et attendre le temps indiqué.

/? Affiche cet écran d’aide.

Remarque : une valeur de délai d’attente égale à -1 signifie qu’une frappe de touche est attendue.

Exemples :
TIMEOUT /?
TIMEOUT /T 10
TIMEOUT /T 300 /NOBREAK
TIMEOUT /T -1

TIMEOUT /T 300 /NOBREAK > nul

 

Logoff, Quser, Qwinsta, Rwinsta

Query the Remote Server for Current Terminal Sessions

To query and list the sessions on the remote session, you could use QUser.exe or QWinsta

1. QUser

QUser command comes with all the latest Windows clients and servers. This will list the sessions of the remote server (or local machine).

NOTE: if you are using Windows XP, you need to add this location into your System path: C:WindowsSystem32DLLCache. To do this, in command prompt, type the following.

SET PATH = %PATH%;C:WindowsSystem32DLLCache;

QUser help shows,

C:Anand>QUser /?
Display information about users logged on to the system.

QUERY USER [username | sessionname | sessionid] [/SERVER:servername]

username Identifies the username.
sessionname Identifies the session named sessionname.
sessionid Identifies the session with ID sessionid.
/SERVER:servername The server to be queried (default is current).

E.g.,

C:>quser /server:MyCitrixSVR
USERNAME SESSIONNAME ID STATE IDLE TIME LOGON TIME
johndoe ica-tcp#966 10 Active 7 7/31/2008 3:04 PM
averagejoe ica-tcp#969 1 Active 9 7/31/2008 3:30 PM
familyman ica-tcp#984 5 Active 1:06 7/31/2008 4:33 PM
normaldude ica-tcp#987 2 Active 4 7/31/2008 6:20 PM

2. QWinsta

QWinsta is little different and better. It has more features and options. It comes with all flavors of Windows. QWinsta command line help displays as,

C:>qwinsta /?
Display information about Terminal Sessions.

QUERY SESSION [sessionname | username | sessionid]
[/SERVER:servername] [/MODE] [/FLOW] [/CONNECT] [/COUNTER]

sessionname Identifies the session named sessionname.
username Identifies the session with user username.
sessionid Identifies the session with ID sessionid.
/SERVER:servername The server to be queried (default is current).
/MODE Display current line settings.
/FLOW Display current flow control settings.
/CONNECT Display current connect settings.
/COUNTER Display current Terminal Services counters information.

E.g.,

C:>qwinsta /server:citrixserver
SESSIONNAME USERNAME ID STATE TYPE DEVICE
0 Disc rdpwd
ica-tcp 65536 Listen wdica
rdp-tcp 65537 Listen rdpwd
console 16 Conn wdcon
ica-tcp#966 johndoe 10 Active wdica
ica-tcp#969 apple 1 Active wdica
ica-tcp#984 averagejoe 5 Active wdica
ica-tcp#987 familyman 2 Active wdica
ica-tcp#989 whoisme 3 Active wdica

You are welcome to try the other options QWinsta provides.

Logoff the Remote Sessions

To Log off the terminal session of the remote server, you can use any one of two command line tools. One of LOGOFF and another one is RWINSTA. Before you log off the remote session, you should know the « Session ID » which you get it from « QUSER » OR « QWINSTA » commands as above stated.

1. Logoff

Logoff command kicks off (logging off) the specified remote session. Log off help shows,

C:>logoff /?
Terminates a session.

LOGOFF [sessionname | sessionid] [/SERVER:servername] [/V]

sessionname The name of the session.
sessionid The ID of the session.
/SERVER:servername Specifies the Terminal server containing the user
session to log off (default is current).
/V Displays information about the actions performed.

E.g.,

C:>logoff /server:infra-apps 1 /v
Logging off session ID 1

2. RWinsta

RWinsta has same parameters and does same thing as log off command. It simply means Reset WINdows STAtion. The help goes as,

C:>RWinsta /?
Reset the session subsytem hardware and software to known initial values.

RESET SESSION {sessionname | sessionid} [/SERVER:servername] [/V]

sessionname Identifies the session with name sessionname.
sessionid Identifies the session with ID sessionid.
/SERVER:servername The server containing the session (default is current).
/V Display additional information.

E.g.,

C:>RWinsta /Server:MyWinServer 1

Note: RWinsta command does not return anything.

Happy Re-setting the remote sessions (Hey, stop cursing your co-workers who didn’t log off their sessions).

Keywords: Reset remote session, Remote Desktop Session