Setup quide for Suse Server (SLES) - MERLIN 5 Janvier 2010 - fpernet Prerequisites ============= MySQL server ------------ Note : included in Suse SLES www:/ # rpm -qa | egrep '^mysql-' mysql-client-5.0.26-12.24.2 mysql-devel-5.0.26-12.24.2 mysql-5.0.26-12.24.2 mysql-shared-5.0.26-12.24.2 Libdbi ------ Note : these packages are not available in SLES. Download them from http://software.opensuse.org/search (search libdbi, libdbi-devel, libdbi-drivers for SLED/SLES10) www:/opt/libdbi # ls libdbi-devel-0.8.3-5.1.i586.rpm libdbi-drivers-dbd-mysql-0.8.3-2.1.i586.rpm libdbi0-0.8.3-5.1.i586.rpm www:/opt/libdbi # rpm --nodeps -Uvh * warning: libdbi-devel-0.8.3-5.1.i586.rpm: Header V3 DSA signature: NOKEY, key ID ee454f98 Preparing... ########################################### [100%] 1:libdbi0 ########################################### [ 33%] /sbin/ldconfig: /usr/lib/libssl.so.0.9.8 is not a symbolic link 2:libdbi-devel ########################################### [ 67%] 3:libdbi-drivers-dbd-mysq########################################### [100%] Php --- Note : php-cli is included in regular php5 package (see /etc/php5/cli/php.ini). These packages are available in SLES. www:/opensoft/merlin # rpm -qa | egrep '^php5-[0-9]|^php5-mysql' php5-5.2.5-9.22 php5-mysql-5.2.5-9.22 MySQL setup =========== Create an empty base, then add a merlin account and grant permissions : www:/opt/merlin-0.6.6 # mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 239 to server version: 5.0.26 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create database merlin; Query OK, 1 row affected (0.00 sec) mysql> grant all privileges on merlin.* to 'merlin'@'localhost' identified by 'merlin'; Query OK, 0 rows affected (0.16 sec) mysql> quit Bye Verify ------ www:/opt/merlin-0.6.6 # mysql -u merlin -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 240 to server version: 5.0.26 Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> show schemas; +--------------------+ | Database | +--------------------+ | information_schema | | merlin | +--------------------+ 2 rows in set (0.00 sec) mysql> quit Bye Compile Merlin ============== Compile and install by using the script supplied by merlin : www:/opt/merlin-0.6.6 # make Before to install, modify the script install-merlin.sh, with : db_setup () { case "$db_type" in mysql) # Create database if it do not exist if [[ ! $(mysql --user=root --password='xxxxx' -e "SHOW DATABASES LIKE '$db_name'") ]]; then echo "Creating database $db_name" mysql --user=root --password='xxxxx' -e "CREATE DATABASE IF NOT EXISTS $db_name" fi # Always set privileges (to be on the extra safe side) mysql --user=root --password='xxxxx' -e \ "GRANT ALL ON $db_name.* TO $db_user@localhost IDENTIFIED BY '$db_pass'" mysql --user=root --password='xxxxx' -e 'FLUSH PRIVILEGES' # Fetch db_version and do upgrade stuff if/when needed query="SELECT version FROM db_version" db_version=$(mysql --user=root --password='xxxxx' $db_name -BNe "$query" 2>/dev/null) case "$db_version" in "") # No db installed mysql --user=root --password='xxxxx' $db_name < $src_dir/db.sql ;; "1") # DB Version is 1 and db should be re-installed (According to AE) mysql --user=root --password='xxxxx' $db_name < $src_dir/db.sql ;; *) # Unknown version, should we handle this? ;; esac ;; *) echo "Unknown database type '$db_type'" echo "I understand only lower-case database types." return 0 ;; esac } Then run this script : www:/opt/merlin-0.6.6 # sh install-merlin.sh --dest-dir=/opensoft/merlin --nagios-cfg=/opensoft/nagios/conf/nagios.cfg --db-type=mysql --db-user=merlin --db-pass=merlin --db-name=merlin Database settings: Type (--db-type): mysql Name (--db-name): merlin Username (--db-user): merlin Password (--db-pass): merlin Path settings: Nagios config file (--nagios-cfg): /opensoft/nagios/conf/nagios.cfg Destination directory (--dest-dir): /opensoft/merlin Base root (--root): Installing the following components: db,files,config,init Does this look ok? [Y/n] Installing Creating database merlin Adding merlin.so as eventbroker to nagios Installation successfully completed You will need to restart Nagios for changes to take effect Verify installation =================== Merlin ------ Files www:/opt/merlin-0.6.6 # cd /opensoft/merlin/ www:/opensoft/merlin # ls db.sql example.conf import.php init.sh install-merlin.sh logs merlin.conf merlin.so merlind object_importer.inc.php RUnlevel Script fro the merlin daemon www:/opensoft/merlin # ls /etc/init.d/merlind /etc/init.d/merlind MySQL ----- Verify tables have been created and mysql merlin account works : www:/opt/merlin-0.6.6 # mysql --user=merlin --password=merlin -e "show tables from merlin" +--------------------------------+ | Tables_in_merlin | +--------------------------------+ | command | | comment | | contact | | contact_contactgroup | | contactgroup | | custom_vars | | db_version | | downtime | | gui_access | | gui_action_log | | host | | host_contact | | host_contactgroup | | host_hostgroup | | host_parents | | hostdependency | | hostescalation | | hostescalation_contact | | hostescalation_contactgroup | | hostgroup | | notification | | program_status | | report_data | | scheduled_downtime | | service | | service_contact | | service_contactgroup | | service_servicegroup | | servicedependency | | serviceescalation | | serviceescalation_contact | | serviceescalation_contactgroup | | servicegroup | | timeperiod | | timeperiod_exclude | +--------------------------------+ Nagios ------ Merlin is used as a broker www:/opt/merlin-0.6.6 # grep merlin /opensoft/nagios/conf/nagios.cfg broker_module=/opensoft/merlin/merlin.so /opensoft/merlin/merlin.conf Modify configuration for Merlin =============================== Startup Script -------------- Modify it like that for Suse and LSB compatibility. Modify the file /etc/init.d/merlind, to have : #!/bin/sh # # Start / stop the Merlin daemon # # chkconfig: 2345 99 01 # ### BEGIN INIT INFO # Provides: Merlin Monitor # Required-Start: $local_fs $network $remote_fs # Required-Stop: $local_fs $network $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: start and stop the merlin daemon # Description: Merlin is an event-distribution system for Nagios ### END INIT INFO . /etc/rc.status prog=merlind BINDIR=/opensoft/merlin CONFIG_FILE=/opensoft/merlin/merlin.conf case "$1" in start) $0 status if test $? = 0; then echo "Merlind is already running ... start cancel !" exit 0 fi echo -ne "Starting Merlind..." startproc $BINDIR/$prog -c $CONFIG_FILE rc_status -v ;; stop) $0 status if test $? = 1; then echo "Merlind is not running ... stop cancel !" exit 0 fi echo -ne "Stopping Merlind ..." killproc -TERM $prog rc_status -v ;; status) echo -ne "Checking Merlind ..." checkproc $prog rc_status -v ;; restart) echo "Restarting Merlind ..." $0 stop $0 start ;; *) echo "Usage: merlind {start|stop|restart|status}" exit 1 ;; esac Create the rc symbolic link, test the script and start merlin : www:/etc/init.d # ln -s /etc/init.d/merlind /sbin/rcmerlind www:/etc/init.d # rcmerlind status Checking Merlind ... unused www:/etc/init.d # rcmerlind start Checking Merlind ... unused Starting Merlind...Logging to '/opensoft/merlin/logs/daemon.log' done www:/etc/init.d # rcmerlind status Checking Merlind ... running www:/etc/init.d # rcmerlind stop Checking Merlind ... running Stopping Merlind ... done www:/etc/init.d # rcmerlind status Checking Merlind ... unused www:/etc/init.d # rcmerlind start Checking Merlind ... unused Starting Merlind...Logging to '/opensoft/merlin/logs/daemon.log' done Put it corretly in runlevels www:/opensoft/merlin # chkconfig merlind 35 Verify merlin daemon log file ------------------------------ www:/opensoft/merlin # tail /opensoft/merlin/logs/daemon.log [1262690136] 6: Successfully ran the previously failed query [1262690136] 6: Primed object states for 0 hosts and 0 services [1262690137] 6: Merlin daemon v0.6.5-beta successfully initialized [1262690137] 4: Handled 0 'ipc' events in -183.224 seconds in: 0, out: 0 [1262692529] 6: dbi_conn_query_null(): Failed to run [SELECT host_name, current_state, state_type FROM merlin.host ORDER BY host_name]: no database connection. Error-code is -3 [1262692529] 6: Attempting to reconnect to database and re-run the query [1262692529] 6: Successfully ran the previously failed query [1262692529] 6: Primed object states for 0 hosts and 0 services [1262692529] 6: Merlin daemon v0.6.5-beta successfully initialized [1262692529] 4: Handled 0 'ipc' events in -2085.460 seconds in: 0, out: 0 Test if port is opened : www:/etc/init.d # netstat -vanutp | grep merlind tcp 0 0 0.0.0.0:15551 0.0.0.0:* LISTEN 18848/merlind Restart Nagios www:/opensoft/merlin # rcnagios stop Stopping can take up to 20 sec in order to be sure all tests are stopped ... Stopping network monitor: nagios done www:/opensoft/merlin # rcnagios start Starting network monitor: nagios done www:/opensoft/merlin # Logging to '/opensoft/merlin/logs/neb.log' [1262692928] 6: Merlin Module Loaded [1262692928] 6: setting connect and disconnect handlers [1262692928] 6: Coredumps in /root [1262692928] 6: Merlin module v0.6.5-beta initialized successfully Verify everything ================= Verify Nagios is connecting to merlin (inbound connection) ------------------------------------- www:/opensoft/merlin # tail /opensoft/merlin/logs/daemon.log [1262690137] 6: Merlin daemon v0.6.5-beta successfully initialized [1262690137] 4: Handled 0 'ipc' events in -183.224 seconds in: 0, out: 0 [1262692529] 6: dbi_conn_query_null(): Failed to run [SELECT host_name, current_state, state_type FROM merlin.host ORDER BY host_name]: no database connection. Error-code is -3 [1262692529] 6: Attempting to reconnect to database and re-run the query [1262692529] 6: Successfully ran the previously failed query [1262692529] 6: Primed object states for 0 hosts and 0 services [1262692529] 6: Merlin daemon v0.6.5-beta successfully initialized [1262692529] 4: Handled 0 'ipc' events in -2085.460 seconds in: 0, out: 0 [1262692939] 6: Accepting inbound connection on ipc socket [1262692939] 6: Executing import command 'php /opensoft/merlin/import.php --nagios-cfg=/opensoft/nagios/conf/nagios.cfg --cache=/opensoft/nagios/state/objects.cache --db-name=merlin --db-user=merlin --db-pass=merlin --db-host=localhost --status-log=/opensoft/nagios/state/status.dat' Verify mysql tables have been populated --------------------------------------- www:/opensoft/merlin # mysql --user=merlin --password=merlin -e "select * from merlin.contact limit 1\G" *************************** 1. row *************************** instance_id: 0 id: 1 contact_name: ant alias: ant host_notifications_enabled: 1 service_notifications_enabled: 1 can_submit_commands: 1 retain_status_information: 1 retain_nonstatus_information: 1 host_notification_period: 24 service_notification_period: 24 host_notification_options: d,u,r service_notification_options: w,u,c,r host_notification_commands: host-notify-by-email service_notification_commands: notify-by-email,service-notify-by-rss email: ant@xxxxx.xxx pager: pagedaemon-admin@l address1: NULL address2: NULL address3: NULL address4: NULL address5: NULL address6: NULL last_host_notification: 1262674389 last_service_notification: 1262686179 Everything runs fine !!! Enjoy ...