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”;
$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 AS host_id, host.hostname AS hostname “
.“FROM (graph_local, host) “
.“WHERE graph_local.host_id=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