[code:1] #!/bin/bash #### var declarations PANDORA_HOME="/opt/pandora" FILES_SERVER_URL="http:// ftp://" # where do I download the installation files from? to be completed ! SERVER_PACK="pandora_server.tar.gz" SERVER_SUBDIR="pandora_server" SERVER_IP="your.pandora_server.ip" SERVER_PORT="22" CONSOLE_PACK="pandora_agent.tar.gz" CONSOLE_SUBDIR="pandora_console" CONSOLE_PATH="/var/www/html" AGENT_PACK="pandora_console.tar.gz" AGENT_SUBDIR="pandora_agent" # ************************************************************** # *********** installation de l'agent ************************** # ************************************************************** echo Generating modules ... # urpmi sshd # urpmi wget # urpmi rsync # mkdir $PANDORA_HOME # cd $PANDORA_HOME # wget $FILES_SERVER_URL/$AGENT_PACK # tar -xzf $AGENT_PACK # mv $PANDORA_HOME/linux $PANDORA_HOME/$AGENT_SUBDIR # we only need linux agent # rm -rf $(ls /opt/pandora/ -I "pan*") # cleaning chown -R root:root $PANDORA_HOME/$AGENT_SUBDIR # root is the owner # Agent is already there but needs custom modules, creating a new pandora_agent.conf: echo "" > $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf # clearing file # *** header *** echo "# Fichero de configuracion base de agentes de Pandora FMS" > $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "# Base config file for Pandora FMS agents" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "# Version 1.2" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "# Licensed under GPL license, 2003-2006 Sancho Lerena" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "# This file was autogenerated by Pandora install script," >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "# GPL Licensed 2006, Denis Chupau Tranquil IT Systems" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "# General Parameters" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "# ==================" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf # *** Agent conf. *** echo "server_ip $SERVER_IP" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "server_port $SERVER_PORT" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "keep_files 1" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "server_path $PANDORA_HOME/$SERVER_SUBDIR/data_in" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "pandora_path $PANDORA_HOME/$AGENT_SUBDIR" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "temporal $PANDORA_HOME/$AGENT_SUBDIR/data_out" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "interval 300" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "debug 0" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "checksum 0" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "agent_name $(hostname)" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "# Modules Definition" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "# ==================" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf # ****** modules definition and generation ******* # **>> monitoring user cpu time : %age=100x(val2-val1)/30000 so each val(%)=val/300 echo "module_begin" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_name cpu_user" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_type generic_data_inc" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_interval 1" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_exec echo $(awk '/^cpu / {print $2}' /proc/stat)/$INTERVAL | bc" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_max 100" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_min 0" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_description user CPU Usage %" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_end" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf # separator # **>> monitoring system cpu time (val(%)=val/300) jiffies counters on 64-bits on 2.6 kernels echo "module_begin" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_name cpu_sys" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_type generic_data_inc" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_interval 1" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_exec echo $(awk '/^cpu / {print $4}' /proc/stat)/$INTERVAL | bc" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_max 100" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_min 0" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_description system CPU Usage %" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_end" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf # **>> monitoring partitions free space for PART in $(df -l | sed -n '/dev/p' | awk '{print $1}'); do NAME=$(df -l $PART | tail -1 | awk '{print $6}' | sed 's///ROOT/') # partition name (/ /home /var ...) echo "module_begin" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_name disk_"$NAME"_free" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_type generic_data" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_interval 2" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_exec df -Pkh $PART | tail -1 | awk '{ print 100-$5 }'" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_max 100" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_min 0" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_description Free disk Percentage of $NAME partition" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_end" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf done # **>> monitoring free RAM echo "module_begin" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_name memfree" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_type generic_data" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_exec echo "scale=1; 100*"$(free | grep Mem | awk '{print $4"/"$2}') | bc" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_description Reports free available RAM" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_end" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf # **>> monitoring free SWAP echo "module_begin" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_name swapfree" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_type generic_data" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_exec echo "scale=1; 100*"$(free | grep Swap | awk '{print $4"/"$2}') | bc" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_end" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf # **>> monitoring processus total echo "module_begin" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_name proctotal" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_type generic_proc" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_exec ps -A | wc -l" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_end" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf # **>> monitoring services in the list below for SERVICE in $(echo httpd snort sshd) do echo "module_begin" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_name service_$SERVICE" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_type generic_proc" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_exec ps -Af | grep $SERVICE | grep -v "grep" | wc -l" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_end" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf done # **>> monitoring syslog's last line echo "module_begin" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_name last_syslog" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_type generic_data_string" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_exec tail -1 /var/log/syslog" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_end" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf # **>> monitoring RAID if [ -x /opt/3ware/tw_cli ] then for CARD in $( /opt/3ware/tw_cli info | grep '^c' | awk '{print $1}' 2> /dev/null) # card name list (c0, c1, ...) do for UNIT in $( /opt/3ware/tw_cli info $CARD | grep '^u' | awk '{print $1}' 2> /dev/null) # card's CARD units name list (u0, u1, ...) do echo "module_begin" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_name raid_"$CARD-$UNIT"_state" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_type generic_data_string" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_interval 2" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_exec /opt/3ware/tw_cli info $CARD | grep '^$UNIT' | awk '{print $1" STATE="$3"("$4"%) TYPE="$2" SIZE="$6"GB CACHE="$7" AVerify="$8" IgnECC="$9}'" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_description State of RAID card $CARD unit $UNIT" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_end" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf done done else echo "3ware RAID utility not found in /opt/3ware/ please download and install it." fi # **>> monitoring uptime echo "module_begin" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_name server_uptime" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_type generic_data_string" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_exec uptime | sed 's/,/ /g' | awk '{print $3" "$4" "$5}'" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_description Grabs the uptime" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_end" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf # **>> monitoring most consuming process echo "module_begin" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_name most_cons_proc" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_type generic_data_string" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_exec ps -eo pcpu,pid,fname,user k pcpu | tail -1 | awk '{print $1"% PID="$2" NAME="$3" USER="$4}'" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_description Get the most CPU consumming task %CPU,PID,name,user" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_end" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf # **>> load average echo "module_begin" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_name average_load" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_type generic_data" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_exec uptime | sed 's/,/ /g' | awk 'BEGIN {FS="load average:"} {print $2}' | awk '{print $2}'" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_description Load average for the last 5 minutes" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_end" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf # **>> last IP adress (external) echo "module_begin" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_name internet_IP" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_type generic_data_string" >> $PANDORA_HOME/$AGENT_SUBDIR/pandora_agent.conf echo "module_exec wget -qO - http://whatismyip.com | grep -i "your ip is" | awk 'BEGIN { FS="
My agent installation script (Linux)
daggett · 15 dic 2006, 17:55 · 5 mensajes · 72 visitas
- Inicio del debate
Oh, cool :-) I will test in today or tomorrow Listen, why did you use root as the owner of pandora? In my humble opinion, it´s much better to use pandora user. It´s not difficult to check if the user is on the system already and if not, create it, from the script, I mean. And another thing, the default www dir is not /var/www/html for every distro, so another cool "plugin" could be detect the distro (If you have seen the pandora_agent.sh you have realised that there´s some code to detect distros, haven´t you? Ok, so, maybe depending on the distro the www PATH could be one or another, is it clear? For example Suse do not use the same path as fedora (either RHEL...) Just some ideas to make that script useful for any Linux distro. Kind regards.
great idea, thanks, I did this script rapidly and to be the simplest it could be, that's why all the variables are preceding the whole script, so users can easily spot the values they have to change to fit their needs. The main reason is that I didn't really need this, and was quiet hurried to achive an automated installation script. So yes I saw the code conserning distrib detection, and this can simply be copy & pasted at the beginning of the script to determine "on the fly" the values stored in the variables. And it seems that all the traffic measuring on the different network interfaces is producing incoherent data... don't know why though, if you could help me debug this... I will repost a new version which will detect the linux distribution, but I won't configure them all in... ;-P I will let it to one user of the different distributions (I'm using Mandriva 2007 and Fedora Core 6). Concerning the script making all the agent files owned to root, it's because all my agents are run by root user with root privileges because certain tasks can't be executed with simple user privileges (some hardware detection), so I made them owned by root. bye for now and thanks to you for your suggestion! Denis Edit: PS: The last lines where added because I didn't see the "learn" option in Pandora Console, But I don't think wee will need it, or it just could be used as a test for checking the SSH communication.
So it's done: (I pasted only the beginning of the file, because the rest of it doesn't change) [code:1]#!/bin/bash #### var declarations and defaults values PANDORA_HOME="/opt/pandora" FILES_SERVER_URL="http:// ftp://" SERVER_PACK="pandora_server.tar.gz" SERVER_SUBDIR="pandora_server" SERVER_IP="your.pandora.server.ip.or.dns.name" SERVER_PORT="22" CONSOLE_PACK="pandora_agent.tar.gz" CONSOLE_SUBDIR="pandora_console" CONSOLE_PATH="/var/www/html" AGENT_PACK="pandora_console.tar.gz" AGENT_SUBDIR="pandora_agent" # Get Linux Distro type and version # SUSE if [ -f "/etc/SuSE-release" ] then OS_VERSION=`cat /etc/SuSE-release | grep VERSION | cut -f 3 -d " "` LINUX_DISTRO=SUSE # *** put your code and vars for SUSE here # CONSOLE_PATH="/var/www/html" # *** between those comments else if [ -f "/etc/lsb-release" ] then OS_VERSION=`cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -f 2 -d "="` LINUX_DISTRO=UBUNTU # *** put your code and vars for UBUNTU here # CONSOLE_PATH="/var/www/html" # *** between those comments else if [ -f "/etc/debian_version" ] then OS_VERSION=`cat /etc/debian_version` OS_VERSION="DEBIAN $OS_VERSION" LINUX_DISTRO=DEBIAN # *** put your code and vars for DEBIAN here # CONSOLE_PATH="/var/www/html" # *** between those comments else if [ -f "/etc/fedora-release" ] then OS_VERSION=`cat /etc/fedora-release | cut -f 4 -d " "` OS_VERSION="FEDORA $OS_VERSION" LINUX_DISTRO=FEDORA # *** put your code and vars for FEDORA here CONSOLE_PATH="/var/www/html" # *** between those comments else if [ -f "/etc/mandriva-release" ] then OS_VERSION=`cat /etc/mandriva-release` LINUX_DISTRO=MANDRIVA # *** put your code and vars for MANDRIVA here CONSOLE_PATH="/var/www/html" # *** between those comments else # Add your distribution detection code here LINUX_DISTRO=GENERIC OS_VERSION=`uname -r` # *** put your code and vars for GENERIC here # *** between those comments fi fi fi fi fi # ************************************************************** # *********** Agent installation ***************************** # ************************************************************** echo Generating modules ... # urpmi sshd # urpmi wget # urpmi rsync # urpli bc # mkdir $PANDORA_HOME # cd $PANDORA_HOME And so on ... (like the first version of the code). I also did a "pandora server" installation script but didn't test it, so it's not been debugged. I 'll post it as a new thread. bye for now!
Great! Debian (and of course, ubuntu) uses as a DocumentRoot: /var/www Suse uses: /srv/www
Entra en tu cuenta para publicar.
