function watchdog_triggers_watchdog in Logging and alerts 6
Same name and namespace in other branches
- 6.2 watchdog_triggers/watchdog_triggers.module \watchdog_triggers_watchdog()
- 7.2 watchdog_triggers/watchdog_triggers.module \watchdog_triggers_watchdog()
- 7 watchdog_triggers/watchdog_triggers.module \watchdog_triggers_watchdog()
Implementation of hook_watchdog().
File
- watchdog_triggers/
watchdog_triggers.module, line 60 - Provides a Trigger and Action integration for watchdog events.
Code
function watchdog_triggers_watchdog($watchdog_message) {
global $user;
$types = trim(variable_get('watchdog_triggers_type', ''));
$users = trim(variable_get('watchdog_triggers_user', ''));
$request_uris = trim(variable_get('watchdog_triggers_request_uri', ''));
$referers = trim(variable_get('watchdog_triggers_referer', ''));
$ips = trim(variable_get('watchdog_triggers_ip', ''));
$severities = variable_get('watchdog_triggers_severity', array(
WATCHDOG_CRITICAL,
WATCHDOG_ALERT,
WATCHDOG_EMERG,
));
if (array_key_exists('-100', $severities)) {
unset($severities['-100']);
}
if ($found_key = array_search('-100', $severities)) {
unset($severities[$found_key]);
}
$messages = trim(variable_get('watchdog_triggers_message', ''));
// Check each value.
// These are cumulative filters, so if one fails - all fail.
$triggered = TRUE;
if (!empty($types)) {
$types = _watchdog_triggers_clean_array(explode(',', $types));
if (!in_array($watchdog_message['type'], $types)) {
$triggered = FALSE;
}
}
if (!empty($users)) {
$users = _watchdog_triggers_clean_array(explode(',', $users));
if (!in_array($watchdog_message['user']->name, $users)) {
$triggered = FALSE;
}
}
if (!empty($request_uris)) {
$request_uris = _watchdog_triggers_clean_array(explode(',', $request_uris));
$match_results = _watchdog_triggers_preg_match_patterns($request_uris, $watchdog_message['request_uri']);
if ($match_results == FALSE) {
$triggered = FALSE;
}
}
if (!empty($referers)) {
$referers = _watchdog_triggers_clean_array(explode(',', $referers));
$match_results = _watchdog_triggers_preg_match_patterns($referers, $watchdog_message['referer']);
if ($match_results == FALSE) {
$triggered = FALSE;
}
}
if (!empty($ips)) {
$ips = _watchdog_triggers_clean_array(explode(',', $ips));
$match_results = _watchdog_triggers_preg_match_patterns($ips, $watchdog_message['ip']);
if ($match_results == FALSE) {
$triggered = FALSE;
}
}
if (count($severities) > 0) {
$severities = _watchdog_triggers_clean_array($severities);
if (!in_array($watchdog_message['severity'], $severities)) {
$triggered = FALSE;
}
}
if (!empty($messages)) {
$messages = _watchdog_triggers_clean_array(explode(',', $messages));
$match_results = _watchdog_triggers_preg_match_patterns($messages, $watchdog_message['message']);
if ($match_results == FALSE) {
$triggered = FALSE;
}
}
if ($triggered === TRUE) {
module_invoke_all('watchdog_triggers', 'watchdog_logged', $user);
}
}