--- cacti.module 2010-08-07 07:03:40.000000000 +1000 +++ cacti.module.new 2010-09-23 08:41:45.158950315 +1000 @@ -88,13 +88,14 @@ function cacti_dispatch($type) { // We matched an IP, so dispatch to the worker functions. if ($allow) { - // Dispatch the queries for supported statistic types - switch ($type) { - case "userstats": - print trim(cacti_userstats()); - // Die so the theme layer is not output. - die; - break; + $value_array = module_invoke_all('cacti_stats', $type); + if (is_array($value_array)) { + $out = array(); + foreach ($value_array as $key => $value) { + $out[] = trim($key) . ':' . trim($value); + } + echo join(' ', $out); + die; } } } @@ -108,21 +109,29 @@ function cacti_dispatch($type) { /** - * Dispatch function. + * hook_cacti_stat - Dispatch function. * Obtain statistics on current logged in users vs. guest users. */ -function cacti_userstats() { - // Add count of active anonymous/authenticated users. Mostly copied from the admin_menu module. - // @see user_block(), user.module - $interval = time() - variable_get('user_block_seconds_online', 900); - $count_anon = sess_count($interval); - $count_auth = db_result(db_query("SELECT COUNT(DISTINCT uid) FROM {sessions} WHERE uid > 0 AND timestamp >= %d", $interval)); - - // Return a count formatted for Cacti - $userstats = "users_anon:" . $count_anon . " users_auth:" . $count_auth; - return $userstats; -} +function cacti_cacti_stats($type) { + switch($type) { + case 'userstats': + // Add count of active anonymous/authenticated users. Mostly copied from the admin_menu module. + // @see user_block(), user.module + $interval = time() - variable_get('user_block_seconds_online', 900); + $count_anon = sess_count($interval); + $count_auth = db_result(db_query("SELECT COUNT(DISTINCT uid) FROM {sessions} WHERE uid > 0 AND timestamp >= %d", $interval)); + + // Return a count formatted for Cacti + return array("users_anon" => $count_anon, "users_auth" => $count_auth); + case 'nodestats': + /* Return count of nodes & comments */ + $count_node = db_result(db_query("SELECT COUNT(DISTINCT nid) FROM {node} WHERE status = 1")); + $count_comment = db_result(db_query("SELECT COUNT(DISTINCT cid) FROM {comments} WHERE status = 0")); + // Return a count formatted for Cacti + return array("node_count" => $count_node, "comment_count" => $count_comment); + } +} /** * Basic validation of an IP. Mainly copied from the restrict_ip module.