Blog Archives

Fixing the monitoring hosts > hosts view in centreon 2.1.4

When opening the Monitoring > Hosts > Hosts view to view all the available and configured hosts in Centreon 2.1.4 you will get a blank result. This happens because there is a coding error in the following file.

/usr/local/centreon/www/include/monitoring/status/Hosts/xml/hostXML.php on line 249

To correct it you need to add a else statement to the if, elseif validation that happens there. So open the file listed above using your fav. editor (vim in my case)

vim /usr/local/centreon/www/include/monitoring/status/Hosts/xml/hostXML.php

Version 2.1.4

Skip to line 249 typing ” :249 ” followed by an enter stroke.
On that line there should be something like;

if (($ndo["last_hard_state_change"] > 0) && ($ndo["last_hard_state_change"] >= $ndo["last_state_change"]))
                        $hard_duration = Duration::toString(time() - $ndo["last_hard_state_change"]);
                else if ($ndo["last_hard_state_change"] > 0)
                        $hard_duration = " N/A ";

Change it to this by adding the part starting from “else”.

if (($ndo["last_hard_state_change"] > 0) && ($ndo["last_hard_state_change"] >= $ndo["last_state_change"]))
                        $hard_duration = Duration::toString(time() - $ndo["last_hard_state_change"]);
                else if ($ndo["last_hard_state_change"] > 0)
                        $hard_duration = " N/A ";
                else
                        $hard_duration = " unknown ";

Version 2.1.8

Goto rule 272 in the same file and locate this piece of code:

if (($ndo["last_hard_state_change"] > 0) && ($ndo["last_hard_state_change"] >= $ndo["last_state_change"]))
                        $hard_duration = Duration::toString(time() - $ndo["last_hard_state_change"]);
                else if ($ndo["last_hard_state_change"] > 0)
                        $hard_duration = " N/A ";

Add the following to make it work.

if (($ndo["last_hard_state_change"] > 0) && ($ndo["last_hard_state_change"] >= $ndo["last_state_change"]))
                        $hard_duration = Duration::toString(time() - $ndo["last_hard_state_change"]);
                else if ($ndo["last_hard_state_change"] > 0)
                        $hard_duration = " N/A ";
                else
                        $hard_duration = "N/A";

This same rule is responsible for the following errors in your apache error_log.

PHP Notice: Undefined variable: hard_duration in /usr/local/centreon/www/include/monitoring/status/Hosts/xml/hostXML.php on line 271, referer: http://centreon.amis.nl/centreon/main.php?p=20102&o=h

This change should fix it for ya.

Grtz, Chris.

Exact globe 396 Runtime & automation errors, selecting “Reports and declaration”

Today we found that “E-Salary” might generate a “Runtime 0” error and an “Automation” error when running in a “dual screen” desktop, afterwhich the mainscreen will freeze.

When exact is opened on the secundair screen you might not be able to run any report / declaration from the right menu options. As an result the main screen will freeze-up and the only solution is restarting exact.

A quick fix is to run exact in the Windows main-screen only! You might be able to identify the main screen by selecting the screen properties, or (if you didnt move the start menu) use the screen that has “menu start” in it.

Good luck, and hopefully this bug will be fixed ūüôā

Templated mail for nagios / centreon.

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

Save code below into a file inside the /usr/local/nagios/libexec/mailbytpl.php

On linux you can use the vi command to do so; i.e. $>vi /usr/local/nagios/libexec/mailbytpl.php

#!/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 you can configure the command into centreon as a ‘notification’ command that takes the following commands:

–mail¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† Should be set, enables the mail functionality
–tplfile=[path to template]¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† ‘The is the html template that will be used
–to=[valid@email.com]¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† Set the receipient
–from=[valid@email.com]¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† Set the sender
–reply=[valid@email.com]¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† Set the return-path
–type=[NOTIFICATIONTYPE]¬†¬†¬†¬†¬†¬†¬†¬†¬† used in the subject of the mail.
–host=[HOSTNAME]¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† used in the subject of the mail.
–[KEY]=[VALUE]¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† add additional information to the template, these fields are autofilled if used in the template.

example:

$USER1$/mailbytpl --mail --tplfile=\$USER1$\mail.tpl --to=example@mail.nl --from=example@mail.nl --reply=no-reply@mail.nl --type=\$NOTIFICATIONTYPE$ --host=\$HOSTNAME$ --IP=\$HOSTADDRESS$ --DOWNTIME=\$HOSTDOWNTIME$

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;

Windows update error?!?

Hi guys,

Uptill reacently we start getting messages in our client system logs stating something like;
The Automatic Updates service terminated with the following error: The class is configured to run as a security id different from the caller. 

To be honost, we tried different aproaches and researched different angles on this issue. Found articles about BITS and other security stuff, but none realy helped. The following is true in our envirnoment.

1. We dont use WSUS.
2. We have a Native 2003 Domain
3. We use Windows XP servicepack 2
4. We do use network policies but for some illusive buisness requirements we dont enforce updates (developers…. )

Here are some things that where true on the issue.
1. We couldnt start or stop the windows update service (wuauserv.dll / wuaueng.dll) and got an access denied message.
2. We couldnt register the various dlls into windows.
3. We couldnt rewrite the BITS entries also getting an access denied message.
4. We couldnt enable “interactive” mode in the security>logon tab of the service getting… Yea an access denied message.

“Update on this Issue”

The problem was somewhat illusive to us, but we found the problem! ūüôā

 The behaviour as described above is caused when a network policy is used to enforce the service configuration (Windows Update Service) itself.

In the Machine portion of a GPO you can browse down to : Computer Configuration >Windows Settings > Security > System Services. Here you can configure various aspects of the winows services, like force the messanger service to be disabled. In our case the Windows Update Service was¬†forced to be Automatic and with thus (check the permisssions button) the rights on that service…

Just remove the policy from the Windows Update service service and control the update service using the aprop. policies found under : Computer Configuration > Administrative templates > Windows Components > Windows Update instead.

This should fix the Id¬†is other then caller issue¬†ūüėČ

Just use the “gpupdate /force” command on the clients that realy need some updates,¬†and or wait till the next logon, or 90¬†Minutes (default gpo refresh time)…

Gl & Rgrds, Chris

IExplorer How to remove the run-once…

Maybe you have allready faced the annoying error where Iexplorer compaints about not having the right permissions to save the settings made in the run-once welcome page. This will result in Iexplorer starting the welcome again the next time iexplorer is ran.

Well thank god we have a work arround for this. To remove the IE7 Welcome page without the need to run it is by editing two registry keys. Please be carefull editing the registry if your not an IT professional. Making wrong changes there might cause windows to stop functioning correctly…

the keys..

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main]
“RunOnceComplete”=dword:00000001
“RunOnceHasShown”=dword:00000001