# Cactiplug.php, problème

**URL:** <https://www.debian-fr.org/t/cactiplug-php-probleme/61775>\
**Category:** Support Debian\
**Created:** [Février 21, 2016, 8:09 UTC](https://www.debian-fr.org/t/cactiplug-php-probleme/61775 "2016-02-21T20:09:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![yamyam](https://www.debian-fr.org/letter_avatar_proxy/v4/letter/y/58956e/32.png) [@yamyam](https://www.debian-fr.org/u/yamyam)\
**Post date:** [Février 21, 2016, 8:09 UTC](https://www.debian-fr.org/t/cactiplug-php-probleme/61775/1 "2016-02-21T20:09:49Z")

</div>

Bonjour,

J’ai installé Nagios sur Debian 6 et ainsi que cacti.  
J’ai voulu testé le plugin cactiplug pour améliorer les performances de mon logiciel superviseur.  
J’ai donc suivit un tutoriel très complet sur le net pour savoir comment lier cacti et nagios.

Malheureusement, j’ai un petit soucis.  
Quand je vais dans Nagios et je clique sur le petit icône représenté par une courbe à côté de l’host, ça me marque que  
"Address IP incorrect or hostname incorrect" voici ma configuration :

cacti version 8.7.g  
nagios version 3.4.1

cactiplug.php

[quote]$cactiurl=“[http://localhost/cacti](http://localhost/cacti)”;  
$database\_default = “cacti”;  
$database\_hostname = “localhost”;  
$database\_username = “cactiadmin”;  
$database\_password = “cactipassword”;

##########

function checkip($address) {  
if(is\_string($address)) {  
# Is it IP…?  
$ip = ip2long($address);  
if( $ip != -1 && $ip !== FALSE) {  
return $ip;  
}  
#…or hostname?  
elseif(gethostbyname($address) != $address) {  
return $address;  
}  
}  
return false;  
}

# Main Code

###########

# Get the IP ip oh the host (GET method)

if (isset($\_GET[“ip”]) && checkip($\_GET[“ip”])) {  
$ip = $\_GET[“ip”];  
$address = gethostbyname($ip); # (We already sanitize it in “checkip” function)  
} else {  
die(“Incorrect IP or hostname”);  
}

# Connect to the Cacti DB

$link = mysql\_connect($database\_hostname, $database\_username, $database\_password)  
or die(“Error while connecting to the DB server”);  
mysql\_select\_db($database\_default)  
or die(“Could not select database”);

# Build and execute the SQL request

$query = “SELECT graph\_local.id AS local\_graph\_id, [host.id](http://host.id) AS host\_id, host.hostname AS hostname “  
.“FROM (graph\_local, host) “  
.“WHERE graph\_local.host\_id=[host.id](http://host.id) AND host.hostname LIKE '”.$ip.”’ OR host.hostname LIKE '”.$address.”’”;  
$result = mysql\_query($query)  
or die(“Query failed”);

# Get the result (the last one)

if (mysql\_num\_rows($result) \> 0) {  
while ($row = mysql\_fetch\_assoc($result)) {  
$action\_url = $cactiurl."/graph\_view.php?action=preview&host\_id=".$row[“host\_id”]."";  
}  
header("Location: ".$action\_url);  
}  
else {  
die(“Host not found, sorry…”);  
}

# Close the DB session

mysql\_free\_result($result);  
mysql\_close($link);

?\> [/quote]

HOST TEMPLATES

[quote]

# Generic host definition template - This is NOT a real host, just a template!

define host{  
name generic-host ; The name of this host template  
notifications\_enabled 1 ; Host notifications are enabled  
event\_handler\_enabled 1 ; Host event handler is enabled  
flap\_detection\_enabled 1 ; Flap detection is enabled  
failure\_prediction\_enabled 1 ; Failure prediction is enabled  
process\_perf\_data 1 ; Process performance data  
retain\_status\_information 1 ; Retain status information across program restarts  
retain\_nonstatus\_information 1 ; Retain non-status information across program restarts  
notification\_period 24x7 ; Send host notifications at any time  
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!  
action\_url /nagios/cactiplug/cactiplug.php?ip=$HOST ADDRESS  
}[/quote]

Ma configuration dans cacti “global.php”

[quote]  
/\* Default database settings\*/  
$database\_type = “mysql”;  
$database\_default = “cacti”;  
$database\_hostname = “localhost”;  
$database\_username = “cactiuser”;  
$database\_password = “cactiuser”;  
$database\_port = “3306”;  
$database\_ssl = false;[/quote]

J’espère que vous pourrez m’aider 🙂
