SE Stuff and the like…


Set / Sync NTP / HWClock on Enterprise Linux (RH/OEL)
November 4, 2009, 10:03 am
Filed under: Linux, Linux Commands, Network Monitoring, VMWare, centreon | Tags: , , , , , , , , ,

Another one of my public notes,


#First Configure your ntp servers for the ntp daemon.
vim /etc/ntp.conf

#Chose the options that are going to work best in your case
#We usualy remove the local clock entry and add two new ntp servers
#Add your local / remote ntp server like this.
#server [server address, either hostname or ip]
server 10.0.0.2 #or
server hostname.domain.ext
#save the settings.

#next check if the ntp daemon is started during system startup for all levels
#that enable networking (235)
chkconfig --list ntpd
ntpd            0:off   1:off   <strong>2:on    3:on</strong>    4:off    <strong>5:on</strong>    6:off

#If ness. add the ntpd daemon to the required levels using;
chkconfig --level 235 ntpd on

#Next sync the system clock with the ntp daemon. BE CAREFULL BEFORE APPYING!
#If the NTP servers time is in the PAST, this step might cause problems when forced
#Readup on ntp how to solve this situation. (yes there is a way ;)   )
ntpdate 10.0.0.2 #You own addres naturally

#Next enable the ntp daemon to take over the sync task.
service ntpd start #or
/etc/init.d/ntpd start

#To wrap it all up, its nice to sync the hardware clock as well using this step.
hwclock --systohc   (read 'System to Hardwareclock')

#in case you need to manually set the timezone correctly
#You might create the correct link from the
#usr/share/zoneinfo/?/? to the /etc/localtime Like this
ln -sf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime

#Hope this helps you as much as it helped me in the past
#Check to see if the NTPd is working can be done
#using the following command
ntpq
ntpq>peers


Installing Nvidia Quadro display drivers on Windows 7 Professional.
November 2, 2009, 1:52 pm
Filed under: Windows 7 Professional, Windows Compontents | Tags: , , , , , , , , , ,

Oke, first off this I will not guarantee that this will not cause any problems in the future, or that this method will work for you!
As you might have noticed there are no supported Quadro drivers for windows 7 at this very moment, But do check the vendor site for any updates before attempting this work arround
.

When to apply
1. Setup halts with an error stating the opperating system isnt correct.

What to try first?
1. Try the Vista Drivers first, they usually install without any error messages. This is still no guarantee that the driver will function properly.

WARNING!
If your display isnt working afterward, do use the “Savemode” option (F8/boot options) to rollback the driver installation. Be sure to understand this before attempting the installation. Creating a restore point might also work out for you.

Work-Arround
1. oke, download the drivers for your system (Mine where on the Dell site as expected ;-)
2. Unpack the drivers to your disk (c:\dell\drivers\#####\, or c:\NVIDIA\)
3. Find the “Setup.exe” file
4. Rightclick it, and find the tab compatibility
5. Select “Windows Vista [distr.] SP3″
6. Select Apply > Ok.
7. Rightclick the setup.exe again (if the next option doesnt show, press hold the left shift key while right clicking)
8. Select “Run as administrator”
9. Follow the Installer, and reboot afterward as usual.

Any keynotes, other solutions, other sources? Please be so kind to share them :)

Good Luck and hope this helped ;-)



Altering the Nagios daemon startup script to include NDO.

previously I wrote an article on how to create a deamon script for ndo. But when you are using Centreon the only “nice” way to do this is by altering the Nagios startupscript to include the ndo part.

Here is what i have done to make this possible.

First i wrote a function to find the PIDs for the ndo deamon process based on a specific config. In this one the config is hardcoded,
but you might also replace the $NagiosNdoConfig with $1 instead and call the function like;

getNdoPid “/usr/local/nagios/etc/yourconfig.cfg”

getNdoPid ()
{
 #Declare a var containing the correct ndo PID, there are processes being forked from ndo so we need to
 #do some awk filtering also to fetch the correct one.
 #Not that the parent process always has a parent pid "1" so we use that to filter the parent from the childs.
 ndoPID=`ps -ef | grep $NagiosNdoConf | grep "?" | awk -F ' '  '{if($3 == '1') print $2}'`
        #next we validate if we got an pid returned to us, and fill a wrapper that we will use like $? that ill convieniently call "ls" LastState.
        if [[ "$ndoPID" == '' ]]; then
            ls=1;
        else
            ls=0;
        fi
}

Next using the getNdoPid function u wrote another two functions to start and to stop the ndo daemon. I choose this method so i can include these function inside the existing start stop scripting used by nagios. In effect when you start nagios, th start case select is used which will call our ndo start script.

The ndo kill function

kill_ndo ()
{
        #Find the actual PID
        if [[ "$ndoPID" == '' ]]; then
             #No process running to kill...
             ls=0;
        else
             kill $ndoPID;
             sleep 2 #parent needs some time to kill the child processes if any
             getNdoPid
             if [[ "$ls" == '1' ]]; then
                   ls=0;
             else
                   ls=1;
             fi
        fi
}

and the start portion…
The ndo start function

start_ndo ()
{
        #always make sure ndo isnt running!
        $NagiosNdo -c $NagiosNdoConf;
        if [[ "$?" == '0' ]]; then
                ls=0;
        else
                ls=1;
        fi
}

Again i am using the ls (laststate) var to save the last state of the executed command. This is important because the state of a command can only be tested right after execution of that command. by using the ls var i make sure i am always testing the correct result. this is because the $? is also overwritten when performing an var assignment, if test etc.

Next I added a few vars for configuration, stuff like where the ndo2db bin is located, and the config file.

NagiosNdo=/usr/sbin/ndo2db;
NagiosNdoConf=/usr/local/nagios/etc/ndo2db.cfg;

naturally the NDO bin could also be found like;
NagiosNdo=`which ndo2db`;
Bu this will require the ndo2db bin to be somewhere in the path var. We are not sure this is always the case because there is no consensus on where these nagios bins should be placed. This may vary from distro to distro and from user to user. In my case, it being placed inside /user/bin this whould also work.

I also extended the functionality of the startupscript by adding new options to start, stop and restart the ndo deamon by using the nagios startupscript. This is what i did.

inside the “case” statement where the “/etc/init.d/nagios args” are tested i added some new options namely “startndo, stopndo, restartndo” and this is what it looks like.

For the option “/etc/init.d/nagios startndo”

 startndo)
                getNdoPid
                if [[ "$ls" == '1' ]]; then
                    start_ndo
                    if [[ "$ls" == '0' ]]; then
                        echo 'NDO deamon started succesfully';
                        exit 0;
                    else
                        echo 'Failed to start NDO, check your logging for more info';
                        exit 1;
                    fi
                else
                    echo "Ndo deamon allready running with PID : $ndoPID";
                    exit 1;
                fi
                ;;

for the “/etc/init.d/nagios stopndo” option

stopndo)
                getNdoPid
                if [[ "$ls" == '1' ]]; then
                     echo "$ls";
                     exit 1;
                else
                     kill_ndo
                     sleep 2 #it needs some time to kill the childs (that get ppid 1 when the parent quits)
                     getNdoPid
                     if [[ "$ls" == '1' ]]; then
                         echo "Ndo stopped succesfully";
                         exit 0;
                     else
                         echo "Unable to kill ndo, please review you logging";
                         exit 1;
                     fi
                fi
                ;;

And a restart option “/etc/init.d/nagios restartndo”

restartndo)
                $0 stopndo
                $0 startndo
                ;;

To include the start and stop options in the nagios start and stop process all you need to do is add the start and or stop options in there.
Here is an example

 start)
                echo -n "Starting nagios:"
                $NagiosBin -v $NagiosCfgFile > /dev/null 2>&1;
                if [ $? -eq 0 ]; then
                        su - $NagiosUser -c "touch $NagiosVarDir/nagios.log $NagiosRetentionFile"
                        rm -f $NagiosCommandFile
                        touch $NagiosRunFile
                        chown $NagiosUser:$NagiosGroup $NagiosRunFile
                        $NagiosBin -d $NagiosCfgFile
                        if [ -d $NagiosLockDir ]; then touch $NagiosLockDir/$NagiosLockFile; fi
                        #chmod 777 $NagiosCommandFile
                        start_ndo
                        echo " done."
                        exit 0
                else
                        echo "CONFIG ERROR!  Start aborted.  Check your Nagios configuration."
                        exit 1
                fi
                ;;
#Stop portion
stop)
                echo -n "Stopping nagios: "

                pid_nagios
                killproc_nagios nagios
                kill_ndo
                # now we have to wait for nagios to exit and remove its
                # own NagiosRunFile, otherwise a following "start" could
                # happen, and then the exiting nagios will remove the
                # new NagiosRunFile, allowing multiple nagios daemons
                # to (sooner or later) run - John Sellens
                #echo -n 'Waiting for nagios to exit .'
                for i in 1 2 3 4 5 6 7 8 9 10 ; do
                    if status_nagios > /dev/null; then
                        echo -n '.'
                        sleep 1
                    else
                        break
                    fi
                done
                if status_nagios > /dev/null; then
                    echo ''
                    echo 'Warning - nagios did not exit in a timely manner'
                else
                    echo 'done.'
                fi

                rm -f $NagiosStatusFile $NagiosRunFile $NagiosLockDir/$NagiosLockFile $NagiosCommandFile
                ;;

        status)
                pid_nagios
                printstatus_nagios nagios
                ;;

Now when i start and stop nagios using the centreon “start / stop / reload” options my ndo daemon is also started / stopped. Ps. This manual uses Nagios 3.0 and Centreon 2.2

This is what a restart looks like ;-)

[root@UX127 var]# service nagios restartndo
Ndo stopped succesfully
NDO deamon started succesfully

Rgrds,



Hide drives in Windows XP.
August 10, 2009, 2:20 pm
Filed under: Uncategorized | Tags: , , , , ,

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\
Explorer]
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\
Explorer]

Drives refference (Binairy), please not that the registry entry (Reg_Dword) is HEX by default.

A: 1, B: 2, C: 4, D: 8, E: 16, F: 32, G: 64, H: 128, I: 256, J: 512, K: 1024, L: 2048, M: 4096, N: 8192, O: 16384, P: 32768, Q: 65536, R: 131072, S: 262144, T: 524288, U: 1048576, V: 2097152, W: 4194304, X: 8388608, Y: 16777216, Z: 33554432, ALL: 67108863

If multiple drives are hidden, then the sum of values apply to the key. I.e.

Hiding “C: & D:”
C: 4 + D: 8 = 12, in which case the regkey should get the value “12″ binairy or “12″ Hex ;-)



Simple VBScript to restart all VMware services
July 30, 2009, 10:36 am
Filed under: VBS, VMWare | Tags: , , , , ,

strComputer = “.”
Set objWMIService = GetObject(“winmgmts:{impersonationLevel=impersonate}!\\”&strComputer&”\root\cimv2″)
Set colListOfServices = objWMIService.ExecQuery(“Select * from win32_Service where Name Like ‘VM%’”)
IntSleep = 15000
For Each objService in colListOfServices
If UCase(Left(objService.name, 1)) > “N” then
objService.StopService()
WScript.Sleep intSleep
objService.StartService()
strMsg = strMsg & vbCr & objService.name & ” Restarted.”
End If
Next

Wscript.Echo strMsg

Sure you can tweak and modify it as you see fit :)



Templated mail for nagios / centreon.

This command enables you to dynamicly create a nice templated mail.

Save this to a file inside the /usr/local/nagios/libexec/

 
 #!/usr/bin/php

<?php

// Lets define the defaults //
$showman = false;
$tpldata = false;
$debug = false;
$settings['from'] = 'centreon@amis.nl';
$settings['type'] = 'notification';
$settings['host'] = '{hostname?}';
$settings['reply'] = 'NULL';

// Dont change anything below! //
// Find and sort all the commandline arguments //
// Make a distinct difference between known settings and arguments later to be passed into the template //

if(@is_array($argv)){
        // Define that the mail setting isnt passed till we realy found it in the argv
        $settings['mail'] = false;
        foreach($argv as $value){
                $keyval = explode("=", $value);
                if(array_key_exists('0', $keyval)){
                        $key = str_replace('--', '', $keyval[0]);
                        if(array_key_exists('1', $keyval)){
                                $val = $keyval[1];
                        }else{
                                $val = NULL;
                        }
                }
                // Default settings we want to fetch //
                switch ($key){
                        case 'mail':
                                $settings['mail'] = true;
                                break;
                        case 'tplfile':
                                $settings['tplfile'] = $val;
                                break;
                        case 'to':
                                $settings['to'] = $val;
                                break;
                        case 'from':
                                $settings['from'] = $val;
                                break;
                        case 'type':
                                $settings['type'] = $val;
                                break;
                        case 'host':
                                $settings['host'] = $val;
                                break;
                        case 'reply':
                                $settings['reply'] = $val;
                        case 'verbose':
                                $debug=true;
                                break;
                        default:
                                // Next to the defaults we fetch additional values...
                                if(!strstr($key, 'mailbytpl.php')){
                                        $arguments[$key] = $val;
                                }
                }
                $keyval = '';
                $key = '';
                $val = '';
        }
        $arguments['DATE'] = date('Y-m-d H:i:s');
}else{
        // If we got no args (default {basename}.ext is allways passed, still need to fix that.//
        // Consider this the spaceholder ;-)  //
        $showman = true;
}
// Validate if all the needed settings where found //
if(!empty($settings['mail']) && !empty($settings['tplfile']) && !empty($settings['to'])){
        // Lets try to open the template file//
        if($settings['mail']){
                if($settings['tplfile']){
                        //Does the directory exist?//
                        if(is_dir(dirname($settings['tplfile']))){
                                if(opendir(dirname($settings['tplfile']))){
                                        if(is_file($settings['tplfile'])){
                                                $tpldata = file($settings['tplfile']);
                                        }else{
                                                die('ERR::Template file doesnt exist or couldnt be opened');
                                        }
                                }else{
                                        die('ERR::Template file directory coudnt be opened. please verify the rights!');
                                }
                        }else{
                                 die('ERR::Template file directory doesnt exist. please verify its existance!');
                        }
                }else{
                        $showman = true;
                }
        }else{
                $showman = true;
        }
        // If we have content from the template file, we need to add the information too it //
        if($tpldata){
                if(count($tpldata) >= 1){
                        // If we found more then 1 rule we can continue //
                        // Lets Generate tablerows too place in the template //
                        $maildata = '';
                        $cc = '0';
                        foreach($arguments as $key => $value){
                                $maildata .= '
<tr>
<td class="datahead'.$cc.'">'.$key.'</td>
<td class="datacontent'.$cc.'">'.$value.'</td>
</tr>
';
                                $cc++;
                        }
                        $maildata .= '<!--Generated by mailbytemplate.php for nagios by AMIS Services BV.-->'."\r\n";
                        $mailbody ='';
                        // If there is an element called $DATAROWS$ then insert the pregenerated block//
                        foreach($tpldata as $lineno => $line){
                                $pattern = '$DATAROWS$';
                                $subject = $line;
                                if(preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE)){
                                        //if there is a match we match it using the arguments//
                                        //Match is found using $matches[0][0]//
                                        $line = str_replace('$DATAROWS$', $maildata, $line);
                                }
                                $mailbody .= $line."\r\n";
                        }
                }else{
                        // We could have loaded an empty file, lets tell the user! //
                        die('Template file was found to be empty');
                }
        }
        if($mailbody){
                // You can add any header you like...
                $headers ="MIME-Version: 1.0 \r\n"; 
                $headers.="From: Centreon <".$settings['from'].">\r\n";
                $headers.="Reply-To: ".$settings['reply']." \r\n";
                $headers.="X-Mailer: PHP/".phpversion()."\r\n";
                $headers.="Content-type: text/html; charset='us-ascii' \r\n";
                $subject =$settings['type'].":: Notification from ".$settings['host']." ...";
                mail($settings['to'], $subject, $mailbody, $headers);
        }
}else{
        $showman = true;
}

if($showman){
        // If the mail command isnt found then show the manual //
        echo "Using this module is fairly simple, first edit the mainfile mailbytpl.php and alter the defaults \r\n";
        echo "Then run the file like the example using the required settings and adding your own using this \r\n";
        echo "Format...\r\n";
        echo "\r\n\r\n";
        echo "{pathtofile}/mailbytpl.php [args]\r\n";
        echo "\r\n\r\n";
        echo "Valid arguments\r\n";
        echo "\t--mail\t\t\t\t\t'Tell the script to execute the mail functionality'\r\n";
        echo "\t--tplfile=[path-to-template]\t\t'The path the the template file that should be used by this script'\r\n";
        echo "\t--to=[valid@mail.ext]\t\t\t'A valid mailaddress of the receipient,\$CONTACTMAIL$ within nagios\r\n";
        echo "\t--from=[valid@mail.ext]\t\t\t'A valid from addres to exclude it from your junkmail folder'\r\n";
        echo "\t--reply=[valid@mail.ext]\t\t'Used as reply-to header to redirect mail to different mailboxes. Defaults to 'NULL'\r\n";
        echo "\t--type=[NOTIFICATIONTYPE]\t\t'Used in the subject of the mail i.e. [type]::notification for [host]'\r\n";
        echo "\t--host=[HOSTNAME]\t\t\t'Used in the subject of the mail i.e. [type]::notification for [host]'\r\n";
        echo "\r\n\r\n";
        echo "Add your information to the template by adding additional custom entries. using the following syntax;\r\n";
        echo "\t--KEY=VALUE\r\n";
        echo "\r\n\r\n";
        echo "Example for nagios:\r\n";
        echo "\$USER1$/mailbytpl --mail --tplfile=\$USER1$\mail.tpl --to=example@mail.nl --from=example@mail.nl --reply=no-reply@mail.nl\r\n";
        echo "--type=\$NOTIFICATIONTYPE$ --host=\$HOSTNAME$ --IP=\$HOSTADDRESS$ --DOWNTIME=\$HOSTDOWNTIME$ --YOUROTHERVAR=\$VALUE$ \r\n";
        echo "\r\n\r\n\r\nScript by : Chris Gralike\r\nCompany : AMIS Services BV\r\n GPL:2009©\r\n";
}
?>

Next create a template file to point to. I called mine mail.tpl

<html>
<head>
<title>Network notification</title>
<style>
body {background-color:#999; text-align:left; font-family:verdana;}
table{border:1px solid #020245; width:100%;}
th{background-color:#020245; color:#fff; border-bottom:1px solid #020245; text-align:left;}
td{border-bottom:1px solid #020245; background-color:#ccc; font-size:11px;}
tr{height:20px;}
#1{border-style:none; background-color:#ccc;}
.2{width:150px;  font-size:12px; font-weight:bold;}
.3{width:3px;}
</style>
</head>
<body>
<table cellspacing=0 align='center'>
$DATAROWS$</table>
</body>
</html>

Well hope this was usefull for ya ;-)  

 

 

 

#!/usr/bin/php
<?php
// Lets define the defaults //
$showman = false;
$tpldata = false;
$debug = false;
$settings['from'] = ‘centreon@amis.nl’;
$settings['type'] = ‘notification’;
$settings['host'] = ‘{hostname?}’;
$settings['reply'] = ‘NULL’;
// Dont change anything below! //
// Find and sort all the commandline arguments //
// Make a distinct difference between known settings and arguments later to be passed into the template //
if(@is_array($argv)){
        // Define that the mail setting isnt passed till we realy found it in the argv
        $settings['mail'] = false;
        foreach($argv as $value){
                $keyval = explode(“=”, $value);
                if(array_key_exists(‘0′, $keyval)){
                        $key = str_replace(‘–’, ”, $keyval[0]);
                        if(array_key_exists(‘1′, $keyval)){
                                $val = $keyval[1];
                        }else{
                                $val = NULL;
                        }
                }
                // Default settings we want to fetch //
                switch ($key){
                        case ‘mail’:
                                $settings['mail'] = true;
                                break;
                        case ‘tplfile’:
                                $settings['tplfile'] = $val;
                                break;
                        case ‘to’:
                                $settings['to'] = $val;
                                break;
                        case ‘from’:
                                $settings['from'] = $val;


Centreon add audioble alert to tacktical overview.

browse to your centreon install location web dir default;

~>cd /usr/local/centreon/www/

browse to the tacticalOverview dir.

~>cd /include/home/tackticalOverview

Open the file tacticalOverview.php

~>vi /tacticalOverview.php

Add the following code in the bottom of the file.


/*
                         * Audiable allert on Warning, Critical, Unknown states.
                         * Values are recalculated because we dont accept NULL as an answer
                         */
                        if(!isset($_SESSION['amis_alert'])){
                                $_SESSION['amis_alert'] = false;
                        }
                        foreach($SvcStat as $key => $val){
                                if(($key == 1) || ($key == 2) || ($key == 3)){
                                        $sum = $val - $svcAck[$key];
                                        if($sum >= 1){
                                                if(!$_SESSION['amis_alert']){
                                                        print('<script>window.open(\'./include/home/tacticalOverview/alert.ihtml\', \'alert\',\'width=180,height=20,scrollbars=no,toolbar=no,location=no\');</script>');
                                                        $_SESSION['amis_alert'] = true;
                                                        break;
                                                }
                                                break;
                                        }else{
                                                print('<script>window.open(\'./include/home/tacticalOverview/closeme.ihtml\', \'alert\',\'width=180,height=20,scrollbars=no,toolbar=no,location=no\');</script>');
                                                $_SESSION['amis_alert'] = false;
                                        }

                                }
                        }

If you want this tidy add additional template entries. I was to lazy for that ;-)

Save the file and add the alert.ihtml

~>vim ./alert.ihtml

Add the following code

<html>
<head></head>
<body>
<div>
<object type="application/x-shockwave-flash" data="../../../mp3player.swf" height="20" width="180"><param name="FlashVars" value="mp3=../../../error.mp3&autoplay=1&loop=1&showslider=0"/></object></div>
</body>

Save the file and add the closeme.ihtml

~>vim closeme.ihtml

Add the following code

<html>
<head></head>
<body>
<script>window.close();</script>
</body>

Go back to the www dir

~>cd /usr/local/centreon/www

download the a nice error.mp3 (yeah you need to rename it ;)

wget http://www.freeinfosociety.com/media/sounds/142.mp3
~>cp ./142.mp3 ./error.mp3

Download the flash player (yeah i renamed this one too :-)

~>wget http://flash-mp3-player.net/medias/player_mp3_maxi.swf
cp ./player_mp3_maxi.swf ./mp3player.swf

This should be all

Hope this helps, and sure do edit the scripts with nicer methods but please do me a favour by keeping us up-to-date with nice addons :D



anywhere, anyhow, anytime google wave!
June 4, 2009, 7:10 pm
Filed under: Uncategorized | Tags: , , , ,

the future for any cyberbully and any form of business fraud.

Good thing that “you n00b” will be automaticly be translated in “you unskilled user” :)

Chech it out yourself at http://wave.google.com

All in all, pretty cool web5 app!!



wait in Bash..

This is an alternative for sleep [i]n[/i]

function wait(){
    BOGUS=`read -n1 -t1 any_key`
    BOGUS=''
}

If you have sleep available, you rather use sleep then this method! i.e.

$N=1;
while :
do
    echo "$N"
    sleep 1
    let N=$N+1;
done


One to think about…
May 19, 2009, 4:42 pm
Filed under: Uncategorized | Tags: , ,

“Performance”

• Are you monitoring freespace or usedspace?
• Is every free CPU cycle a wasted one, or one waiting to be used?
• Do you like mountains or Hills in your graphs?
• Capacity planning? or Performance tuning?