You are here

watchdog_rules.module in Logging and alerts 7

Provides a Rules integration for wachdog events.

File

watchdog_rules/watchdog_rules.module
View source
<?php

// $Id$

/**
 * @file
 * Provides a Rules integration for wachdog events.
 */

/**
 * Implements hook_watchdog().
 */
function watchdog_rules_watchdog($watchdog_message) {
  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'], $watchdog_message['message']);
}

/**
 * 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;
  }
}