summaryrefslogtreecommitdiff
path: root/modules/watchdog/watchdog.module
blob: e1c9b416735f261f233c5fdcb70d41ee5b6ea988 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
// $Id$

function watchdog_help() {
 ?>
  <P>The watchdog module monitors your website, captures system events in a log and records them to be reviewed by an authorized individual at a later time.  The watchdog log is simply a list of events recorded during operation and contains usage data, performance data, errors, warnings and operational information.  It is vital to check the watchdog report on a regular basis as it is often the only way to tell what is going on.</P>
  <P>To ease administration, the watchdog will automatically discard old log entries.</P>
 <?php
}

function watchdog_system($field){
  $system["description"] = t("Logs and records system events.");
  return $system[$field];
}

function watchdog_perm() {
  return array("administer watchdog");
}

function watchdog_link($type) {
  if ($type == "admin" && user_access("administer watchdog")) {
    $help = "The watchdog module monitors your website, captures system events in a log and records them to be reviewed by an authorized individual at a later time.  The watchdog log is simply a list of events recorded during operation and contains usage data, performance data, errors, warnings and operational information. It is vital to check the watchdog report on a regular basis as it is often the only way to tell what is going on.";

    menu_add("site monitoring", url("admin/watchdog"), "Monitor your site.", NULL, NULL, 2);
     menu_add("watchdog", url("admin/watchdog/list/all"), "Display system events.", $help, "site monitoring", 1, 1);
      menu_add("user messages", url("admin/watchdog/list/user"), "Display system events", $help, "watchdog");
      menu_add("regular messages", url("admin/watchdog/list/regular"), "Display system events", $help, "watchdog");
      menu_add("special messages", url("admin/watchdog/list/special"), "Display system events", $help, "watchdog");
      menu_add("warning messages", url("admin/watchdog/list/warning"), "Display system events", $help, "watchdog");
      menu_add("error messages", url("admin/watchdog/list/error"), "Display system events", $help, "watchdog");
      menu_add("httpd messages", url("admin/watchdog/list/httpd"), "Display system events", $help, "watchdog");
  }
}

function watchdog_conf_options() {
  $period = array(3600 => format_interval(3600), 10800 => format_interval(10800), 21600 => format_interval(21600), 32400 => format_interval(32400), 43200 => format_interval(43200), 86400 => format_interval(86400), 172800 => format_interval(172800), 259200 => format_interval(259200), 604800 => format_interval(604800), 1209600 => format_interval(1209600), 2419200 => format_interval(2419200), 1000000000 => t("Never"));
  $output .= form_select(t("Discard entries older than"), "watchdog_clear", variable_get("watchdog_clear", 604800), $period, t("The time watchdog entries should be kept.  Older entries will be automatically discarded.  Requires crontab."));
  return $output;
}

function watchdog_cron() {
  db_query("DELETE FROM watchdog WHERE ". time() ." - timestamp > ". variable_get("watchdog_clear", 604800));
}

function watchdog_overview($type) {
  $color = array("user" => "#FFEEAA", "message" => "#FFFFFF", "special" => "#A49FFF", "warning" => "#FFAA22", "httpd" => "#99DD99", "error" => "#EE4C4C");
  $query = array("user" => "WHERE type = 'user'", "regular" => "WHERE type = 'message'", "special" => "WHERE type = 'special'", "warning" => "WHERE type = 'warning'", "error" => "WHERE type = 'error'", "httpd" => "WHERE type = 'httpd'", "actions" => "WHERE link != ''");

  $result = pager_query("SELECT w.*, u.name, u.uid FROM watchdog w LEFT JOIN users u ON w.uid = u.uid ". ($type ? $query[$type] : "") ." ORDER BY w.timestamp DESC", 100);

  $output .= "<table>";
  $output .= " <tr><th>" . t("date") . "</th><th>" . t("event") . "</th><th>" . t("user") . "</th><th colspan=\"2\">" . t("operations") . "</th></tr>";
  while ($watchdog = db_fetch_object($result)) {
    if ($background = $color[$watchdog->type]) {
      $output .= " <tr bgcolor=\"$background\"><td nowrap=\"nowrap\">". format_date($watchdog->timestamp, "small") ."</td><td>". substr(strip_tags($watchdog->message), 0, 64) ."</td><td align=\"center\">". format_name($watchdog) ."</a></td><td align=\"center\">$watchdog->link</td><td align=\"center\">". l(t("view details"), "admin/watchdog/view/$watchdog->wid") ."</td></tr>";
    }
  }

  if ($pager = pager_display(NULL, 100, 0, "admin")) {
    $output .= " <tr><td align=\"center\" colspan=\"4\">$pager</td></tr>";
  }

  $output .= "</table>";

  return $output;
}

function watchdog_view($id) {

  $result = db_query("SELECT w.*, u.name, u.uid FROM watchdog w LEFT JOIN users u ON w.uid = u.uid WHERE w.wid = '%d'", $id);

  if ($watchdog = db_fetch_object($result)) {
    $output .= "<table border=\"1\" cellpadding=\"2\" cellspacing=\"2\">";
    $output .= " <tr><th>". t("Type") ."</th><td>$watchdog->type</td></tr>";
    $output .= " <tr><th>". t("Date") ."</th><td>". format_date($watchdog->timestamp, "large") ."</td></tr>";
    $output .= " <tr><th>". t("User") ."</th><td>". format_name($watchdog) ."</td></tr>";
    $output .= " <tr><th>". t("Location") ."</th><td>$watchdog->location</td></tr>";
    $output .= " <tr><th>". t("Message") ."</th><td>$watchdog->message</td></tr>";
    $output .= " <tr><th>". t("Hostname") ."</th><td>$watchdog->hostname</td></tr>";
    $output .= "</table>";

    return $output;
  }
}

function watchdog_admin() {

  if (user_access("administer watchdog")) {
    switch (arg(2)) {
      case "help":
        watchdog_help();
        break;
      case "view":
        print watchdog_view(check_input(arg(3)));
        break;
      default:
        print watchdog_overview(arg(3));
    }
  }
  else {
    print message_access();
  }
}

?>