/*
- NAME : gcm_daemon
- AUTHOR : Brenno J.S.A.A.F. de Winter
- De Winter Information Solutions
- COPYRIGHT : 2002 - De Winter Information Solutions,
- Brenno J.S.A.A.F. de Winter
+ NAME : gcm_daemon
+ AUTHOR : Brenno J.S.A.A.F. de Winter
+ De Winter Information Solutions
+ COPYRIGHT : 2002 - De Winter Information Solutions,
+ Brenno J.S.A.A.F. de Winter
* DATES *
- First : November 8th 2002
+ First : November 8th 2002
Gnucomo-0.0.3: December 6th 2002
$Log: gcm_daemon.php,v $
- Revision 1.13 2003-08-14 10:22:42 arjen
+ Revision 1.14 2003-09-01 06:51:07 arjen
+ Accept command argument '-c config' to use an alternate
+ gnucomo configuration.
+
+ Revision 1.13 2003/08/14 10:22:42 arjen
Disabled DEBUG output
Revision 1.12 2003/08/05 07:46:37 arjen
*/
-// $Id: gcm_daemon.php,v 1.13 2003-08-14 10:22:42 arjen Exp $
+// $Id: gcm_daemon.php,v 1.14 2003-09-01 06:51:07 arjen Exp $
ini_set('include_path', '.:./classes:../phpclasses');
+ini_set('html_errors', 'false');
//Tell the log that we're up.
define_syslog_variables();
-openlog("gnucomo", LOG_PID, LOG_DAEMON);
-syslog(LOG_INFO, "gcm_daemon started");
require_once "gnucomo_config.php";
require_once "db.class.php";
require_once "gnucomo.process_log.php";
// Set the standard variables //
-$project_name = "gnucomo"; //name of the entire project
-$app_name = "gcm_daemon"; //name of the application running
-$developrelease = "FALSE"; //Indicates if special debug settings are needed
-$db_version = 42; //The db_version indicates what the level of
- //the database should be. If the database is
- //old an update will be generated.
-$gcmd_version = 5; //This value indicates the active version of the gcm_daemon,
- //which is saved in the database. Log records that were not
- //recognized before will now be recognized. The version doesn't
- //mean anything in the overall gnucomo project.
+
+$project_name = "gnucomo"; // name of the entire project
+$app_name = "gcm_daemon"; // name of the application running
+$developrelease = "FALSE"; // Indicates if special debug settings are needed
+$db_version = 42; // The db_version indicates what the level of
+ // the database should be. If the database is
+ // old an update will be generated.
+$gcmd_version = 5; // This value indicates the active version of
+ // the gcm_daemon, which is saved in the database.
+ // Log records that were not recognized before
+ // will now be recognized. The version doesn't
+ // mean anything in the overall gnucomo project.
//Avoid time-limit issues
set_time_limit(0);
+// Scan the command arguments
+
+for ($argi = 1; $argi < $argc; $argi++)
+{
+ switch ($argv[$argi])
+ {
+ case "-c":
+ $argi++;
+ $project_name = $argv[$argi];
+ break;
+
+ default:
+ echo "Usage: gcm_daemon [-c configname]\n";
+ exit();
+ break;
+ }
+}
// Read the database settings //
$class_settings = new gnucomo_config();
-$class_settings->read($project_name);
+if (!$class_settings->read($project_name))
+{
+ echo "Can not read Gnucomo configuration file for $project_name.\n";
+ exit();
+}
+
+openlog("gnucomo", LOG_PID, LOG_DAEMON);
+syslog(LOG_INFO, "gcm_daemon started");
//Open an connection to the database
$dbms_type = $class_settings->find_parameter("database", "type");
$dbms->db_password = $dbms_password;
$dbms->db_connect($class_settings->database());
-if ($dbms->have_db_connection() == "FALSE") {
- exit ("Database connection failed.");
-} else {
- //The database connection has been made.
- $dbms_working = copy_db_class($dbms, $class_settings->database());
+if ($dbms->have_db_connection() == "FALSE")
+{
+ exit ("Database connection failed.");
+}
+else
+{
+ // The database connection has been made.
+ $dbms_working = copy_db_class($dbms, $class_settings->database());
}
-//Verify if the database is up-to-date by checking the versionnumber
+// Verify if the database is up-to-date by checking the versionnumber
+
$local_sql = "SELECT setting_value FROM db_value WHERE setting = 'db_version' ";
$dbms->query($local_sql);
-if ($dbms->fetch_row() == "TRUE") {
+if ($dbms->fetch_row() == "TRUE")
+{
$active_version = $dbms->db_result_row[0];
- //Update the database to the most recent version.
- if ($active_version < $db_version) {
+ // Update the database to the most recent version.
+
+ if ($active_version < $db_version)
+ {
include ("gnucomo_db_version.php");
}
-} else {
+}
+else
+{
syslog (LOG_INFO, "Couldn't initialize database version. Is this a gnucomo database?");
die ("Couldn't initialize database version.\n");
}
-//If there is a new gcm_daemon_version the logrecords that couldn't be understood can be
-//reprocessed. For this reason processed is now changed to false again for not recognized
-//records.
-$local_sql = "SELECT setting_value FROM db_value WHERE setting = 'gcm_daemon_version'";
+// If there is a new gcm_daemon_version the logrecords that couldn't be
+// understood can be reprocessed. For this reason processed is now changed
+// to false again for not recognized records.
+
+$local_sql = "SELECT setting_value FROM db_value
+ WHERE setting = 'gcm_daemon_version'";
$dbms->query($local_sql);
-if ($dbms->fetch_row() == "TRUE") {
- if ($dbms->db_result_row[0] < $gcmd_version) {
+if ($dbms->fetch_row() == "TRUE")
+{
+ if ($dbms->db_result_row[0] < $gcmd_version)
+ {
//Reactive log-records that weren't understood earlier.
- $local_sql = "UPDATE log SET processed = false WHERE logid NOT IN (SELECT DISTINCT logid FROM log_adv)";
+
+ $local_sql = "UPDATE log SET processed = false
+ WHERE logid NOT IN (SELECT DISTINCT logid FROM log_adv)";
$dbms->query($local_sql);
//Update de gcm_daemon version in the database
}
-//Now we loop the tasks that we have to do.
+// Now we loop the tasks that we have to do.
-do {
+do
+{
// Gather the statistics for each object
}
//At this place we start processing new log-lines
+
process_log ();
- //notificationstats(); // This function is obsolete
find_notifications();
- $keep_running = 'FALSE';
+ $keep_running = false;
-} while ($keep_running == 'TRUE');
+} while ($keep_running == true);
//Tell the log that we're ending our efforts in a nice way
+
syslog (LOG_INFO, "gcm_daemon ended nicely");
-function process_log () {
+function process_log ()
+{
/* This function will walk through the log-records that haven't been processed
* first a snapshot will be created of a the non-processed records.
* INPUT : NONE
* OUTPUT : NONE
*/
+
global $dbms;
global $dbms_working;
global $class_settings;
- //Find records in log that still have to be processed.
+ // Find records in log that still have to be processed.
$local_sql = "SELECT setting_value FROM db_value WHERE setting = 'log_processing'";
$dbms->query($local_sql);
- if ($dbms->fetch_row() == "TRUE") {
+ if ($dbms->fetch_row() == "TRUE")
+ {
$last_log = $dbms->db_result_row[0];
}
//Query the log-table
- $local_sql = "SELECT * FROM log WHERE logid > CAST(".$last_log." AS BIGINT) order by logid";
+ $local_sql = "SELECT * FROM log WHERE logid > CAST(".$last_log." AS BIGINT)
+ ORDER BY logid";
$dbms->query($local_sql);
//Update the log-statistics in the object-table
" AS BIGINT) AND logid < CAST (" . $local_upper_row . " AS BIGINT) GROUP BY objectid";
$local_statistics_db->query ($local_sql);
- //Loop the objects
- for ($i = 1; $i <= $local_statistics_db->num_rows(); $i++) {
+ // Loop the objects
+ for ($i = 1; $i <= $local_statistics_db->num_rows(); $i++)
+ {
$local_object_row = $local_statistics_db->fetch_row();
+
$local_sql = "UPDATE object SET log_count = log_count + " .
$local_statistics_db->db_result_row[0] . " WHERE objectid = '" .
- $local_statistics_db->db_result_row[1] . "'";
+ $local_statistics_db->db_result_row[1] . "'";
+
$local_findobject_db->query($local_sql);
}
$local_counter = 0;
- if ($dbms->num_rows() > 0) {
+ if ($dbms->num_rows() > 0)
+ {
//Create a database connection for changes in the database.
$dbms_changes = copy_db_class($dbms, $class_settings->database());
- if ($dbms_changes->have_db_connection() == 'TRUE') {
+ if ($dbms_changes->have_db_connection() == 'TRUE')
+ {
$local_sql = 0 ;
$local_sql_statistics = "";
$local_object_os = "";
$local_object_os_version = "";
- while ($local_counter < $dbms->num_rows()) {
+ while ($local_counter < $dbms->num_rows())
+ {
$local_return_row = $dbms->fetch_row();
- if ($local_return_row == 'TRUE') {
- //Work on active rows
+ if ($local_return_row == 'TRUE')
+ {
+ // Work on active rows
$local_log_id = $dbms->db_result_row[0];
- $local_sql_findobject = "SELECT os, os_version FROM object WHERE objectid = '".$dbms->db_result_row[1]."'";
+ $local_sql_findobject = "SELECT os, os_version FROM object
+ WHERE objectid = '".$dbms->db_result_row[1]."'";
$local_findobject_db->query($local_sql_findobject);
$local_findobject_result = $local_findobject_db->fetch_row();
- if ($local_findobject_result == 'TRUE') {
-
- //Now work on the OS again
+ if ($local_findobject_result == 'TRUE')
+ {
+
+ // Now work on the OS again
$local_object_os = $local_findobject_db->db_result_row[0];
- if ($local_object_os == "") {
+ if ($local_object_os == "")
+ {
$local_object_os = "Linux";
$local_object_os_version = "Unknown assuming Linux";
- } else {
+ }
+ else
+ {
$local_object_os_version = $local_findobject_db->db_result_row[1];
}
}
- switch (strtolower($local_object_os)) {
- case "linux":
+ switch (strtolower($local_object_os))
+ {
+ case "linux":
$local_process_return = linux_log ();
break;
- default:
+ default:
syslog (LOG_INFO, "Couldn't find suitable OS for processing the logline");
break;
- }
+ }
- if ($local_process_return <> 'TRUE') {
- $local_process_return = 'FALSE';
+ if ($local_process_return != 'TRUE')
+ {
+ $local_process_return = 'FALSE';
}
- } else {
+ }
+ else
+ {
break;
$local_counter++;
}
- //Register that the logrecords have been processed.
- $local_sql = "UPDATE db_value SET setting_value = '".$local_log_id."' where setting = 'log_processing'";
+ // Register that the logrecords have been processed.
+ $local_sql = "UPDATE db_value SET setting_value = '"
+ .$local_log_id."' where setting = 'log_processing'";
$dbms->query($local_sql);
- //Update the statistics for the object-table
+ // Update the statistics for the object-table
- } else {
+ }
+ else
+ {
syslog (LOG_INFO, "Couldn't clone database connection.");
die ("Couldn't reconnect to the database.\n");
- }
- }
+ }
+ }
}
UpdateStatistic($objectid, 'logs', $cnt->count);
}
-function notificationstats ()
-{
-
- // OBSOLETE //
-
-/* This routine will determine how many new notifications have arrived and will
- * update the statistics in the object-table to keep the performance acceptable
- * INPUT : NONE
- * OUTPUT : NONE
- */
-
- global $dbms, $class_settings;
-
- //Find records in log that still have to be processed.
- $local_sql = "SELECT setting_value FROM db_value WHERE setting = 'last_notification'";
- $dbms->query($local_sql);
- $local_dbms = copy_db_class($dbms, $class_settings->database());
-
- //Determine the last notification
- if ($dbms->fetch_row() == "TRUE") {
- $last_notification = $dbms->db_result_row[0];
- }
-
- //Determine how many records we are going to analyse.
- $local_sql = "SELECT MAX(notificationid) FROM notification " .
- "WHERE notificationid > CAST ('" . $last_notification . "' AS BIGINT)";
- $dbms->query($local_sql);
-
- //Only process data if there are new notifications
- if ($dbms->fetch_row() == "TRUE") {
- if (intval($dbms->db_result_row[0])>0) {
- $local_upper = $dbms->db_result_row[0] + 1;
- $local_max = $dbms->db_result_row[0];
- $local_sql = "SELECT COUNT(objectid), objectid FROM notification " .
- "WHERE notificationid > CAST ('" . $last_notification ."' AS BIGINT) " .
- "AND notificationid < CAST ('" . $local_upper .
- "' AS BIGINT) GROUP BY objectid";
- $dbms->query($local_sql);
-
-
- for ($i=0; $i < $dbms->num_rows(); $i++) {
- $dbms->fetch_row();
-
- $local_sql = "UPDATE object SET notification_count = notification_count + " . $dbms->db_result_row[0] .
- " WHERE objectid = '" . $dbms->db_result_row[1] . "'";
- $local_dbms->query($local_sql);
- }
-
- $local_sql = "UPDATE db_value SET setting_value = '" . $local_max .
- "' WHERE setting = 'last_notification'";
- $dbms->query($local_sql);
- }
- }
-}
function find_notifications () {
* OUTPUT : NONE
*/
- global $dbms;
+ global $dbms;
- //Find checks that have to be executed.
- $local_sql = "select * from notification_check where age(last_execution) > time_between_executions";
- $dbms->query($local_sql);
- for ($i=0; $i<$dbms->num_rows(); $i++) {
- //A check has been found that has to be executed
- $dbms->fetch_row();
- }
+ // Find checks that have to be executed.
+ $local_sql = "select * from notification_check where
+ age(last_execution) > time_between_executions";
+ $dbms->query($local_sql);
+
+ for ($i=0; $i<$dbms->num_rows(); $i++)
+ {
+ // A check has been found that has to be executed
+ $dbms->fetch_row();
+ }
}
?>