watchdog_rules.module in Logging and alerts 7.2
Same filename and directory in other branches
Provides a Rules integration for wachdog events.
File
watchdog_rules/watchdog_rules.moduleView source
<?php
// $Id$
/**
* @file
* Provides a Rules integration for wachdog events.
*/
/**
* Implements hook_watchdog().
*/
function watchdog_rules_watchdog($watchdog_message) {
// Make sure we do not provide NULL values, as Rules module doesn't like them.
// @see http://drupal.org/node/1497534
foreach ($watchdog_message as $key => $value) {
if (is_null($value)) {
$watchdog_message[$key] = '';
}
}
// Make sure that 'variables' is array, because t() required array value.
if (empty($watchdog_message['variables'])) {
$watchdog_message['variables'] = array();
}
rules_invoke_event('watchdog_rules', $watchdog_message['user'], $watchdog_message['type'], $watchdog_message['request_uri'], $watchdog_message['referer'], $watchdog_message['ip'], $watchdog_message['timestamp'], $watchdog_message['severity'], $watchdog_message['link'], t($watchdog_message['message'], $watchdog_message['variables']));
}
/**
* Implements hook_token_info().
*/
function watchdog_rules_token_info() {
$type = array(
'name' => t('Watchdog tokens'),
'description' => t('Watchdog tokens'),
'needs-data' => 'watchdog',
);
$watchdog['type'] = array(
'name' => t("Watchdog type"),
'description' => t("The type of the watchdog event."),
);
$watchdog['request_uri'] = array(
'name' => t("Watchdog request URI"),
'description' => t('The request URI for the page the event happened in.'),
);
$watchdog['referer'] = array(
'name' => t("Watchdog referer"),
'description' => t('The page that referred the user to the page where the event occurred.'),
);
$watchdog['ip'] = array(
'name' => t("Watchdog ip"),
'description' => t('The IP address where the request for the page came from.'),
);
$watchdog['timestamp'] = array(
'name' => t("Watchdog timestamp"),
'description' => t('The UNIX timetamp of the date/time the event occurred.'),
);
$watchdog['severity'] = array(
'name' => t("Watchdog severity"),
'description' => t('The degree of severity of the event.'),
);
$watchdog['link'] = array(
'name' => t("Watchdog link"),
'description' => t('An informational link provided by the module calling watchdog.'),
);
$watchdog['message'] = array(
'name' => t("Watchdog message"),
'description' => t('The text of the message to be logged.'),
);
return array(
'types' => array(
'watchdog' => $type,
),
'tokens' => array(
'watchdog' => $watchdog,
),
);
}
/**
* Implements hook_tokens().
*/
function watchdog_rules_tokens($type, $object = NULL, $options = array()) {
$tokens = array();
if ($type == 'watchdog' || $type == 'all') {
$tokens = array(
'type' => $object['type'],
'request_uri' => $object['request_uri'],
'referer' => $object['referer'],
'ip' => $object['ip'],
'timestamp' => $object['timestamp'],
'severity' => $object['severity'],
'link' => $object['link'],
'message' => $object['message'],
);
return $tokens;
}
}
Functions
Name | Description |
---|---|
watchdog_rules_tokens | Implements hook_tokens(). |
watchdog_rules_token_info | Implements hook_token_info(). |
watchdog_rules_watchdog | Implements hook_watchdog(). |