watchdog.module 3.61 KB
Newer Older
Dries's avatar
 
Dries committed
1
<?php
Dries's avatar
 
Dries committed
2

Dries's avatar
 
Dries committed
3 4 5
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>
Dries's avatar
 
Dries committed
6
  <P>To ease administration, the watchdog will automatically discard old log entries.</P>
Dries's avatar
 
Dries committed
7
 <?php
Dries's avatar
 
Dries committed
8 9
}

Dries's avatar
CHANGES  
Dries committed
10
function watchdog_conf_options() {
Dries's avatar
 
Dries committed
11
  $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"));
Dries's avatar
 
Dries committed
12 13 14 15
  $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;
}

Dries's avatar
 
Dries committed
16
function watchdog_cron() {
Dries's avatar
 
Dries committed
17
  db_query("DELETE FROM watchdog WHERE ". time() ." - timestamp > ". variable_get("watchdog_clear", 604800));
Dries's avatar
 
Dries committed
18
}
Dries's avatar
 
Dries committed
19

Dries's avatar
 
Dries committed
20
function watchdog_overview() {
Dries's avatar
 
Dries committed
21
  $colors = array(message => "#FFFFFF", special => "#836FFF", warning => "#FFAA22", error => "#EE2C2C");
Dries's avatar
 
Dries committed
22

Dries's avatar
 
Dries committed
23
  $result = db_query("SELECT w.*, u.userid FROM watchdog w LEFT JOIN users u ON w.user = u.id ORDER BY timestamp DESC LIMIT 1000");
Dries's avatar
 
Dries committed
24

Dries's avatar
 
Dries committed
25
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
Dries's avatar
 
Dries committed
26
  $output .= " <TR><TH>date</TH><TH>type</TH><TH>message</TH><TH>user</TH><TH>operations</TH></TR>\n";
Dries's avatar
 
Dries committed
27
  while ($watchdog = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
28 29 30
    if ($color = $colors[$watchdog->type]) {
      $output .= " <TR BGCOLOR=\"$color\"><TD>". format_date($watchdog->timestamp) ."</TD><TD ALIGN=\"center\">$watchdog->link</TD><TD>". substr(check_output($watchdog->message), 0, 50) ."</TD><TD ALIGN=\"center\">". format_username($watchdog->userid) ."</A></TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=watchdog&op=view&id=$watchdog->id\">details</A></TD></TR>\n";
    }
Dries's avatar
 
Dries committed
31 32 33
  }
  $output .= "</TABLE>\n";

Dries's avatar
 
Dries committed
34
  return $output;
Dries's avatar
 
Dries committed
35 36 37
}

function watchdog_view($id) {
Dries's avatar
 
Dries committed
38
  $result = db_query("SELECT l.*, u.userid FROM watchdog l LEFT JOIN users u ON l.user = u.id WHERE l.id = '$id'");
Dries's avatar
 
Dries committed
39 40 41

  if ($watchdog = db_fetch_object($result)) {
    $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">\n";
Dries's avatar
 
Dries committed
42
    $output .= " <TR><TH>Type:</TH><TD>". check_output($watchdog->type) ."</TD></TR>\n";
Dries's avatar
 
Dries committed
43 44
    $output .= " <TR><TH>Date:</TH><TD>". format_date($watchdog->timestamp, "large") ."</TD></TR>\n";
    $output .= " <TR><TH>User:</TH><TD>". format_username($watchdog->userid) ."</TD></TR>\n";
Dries's avatar
 
Dries committed
45 46 47
    $output .= " <TR><TH>Location:</TH><TD>". check_output($watchdog->location). "</TD></TR>\n";
    $output .= " <TR><TH>Message:</TH><TD>". check_output($watchdog->message) ."</TD></TR>\n";
    $output .= " <TR><TH>Hostname:</TH><TD>". check_output($watchdog->hostname) ."</TD></TR>\n";
Dries's avatar
 
Dries committed
48
    $output .= "</TABLE>\n";
Dries's avatar
 
Dries committed
49

Dries's avatar
 
Dries committed
50 51
    return $output;
  }
Dries's avatar
 
Dries committed
52 53
}

Dries's avatar
 
Dries committed
54 55 56
function watchdog_admin() {
  global $op, $id, $order;

Dries's avatar
 
Dries committed
57 58
  print "<SMALL><A HREF=\"admin.php?mod=watchdog\">overview</A> | <A HREF=\"admin.php?mod=watchdog&op=help\">help</A></SMALL><HR>\n";

Dries's avatar
 
Dries committed
59
  switch ($op) {
Dries's avatar
 
Dries committed
60 61 62
    case "help":
      watchdog_help();
      break;
Dries's avatar
 
Dries committed
63
    case "view":
Dries's avatar
 
Dries committed
64
      print watchdog_view(check_input($id));
Dries's avatar
 
Dries committed
65 66
      break;
    default:
Dries's avatar
 
Dries committed
67
      print watchdog_overview();
Dries's avatar
 
Dries committed
68 69 70 71
  }
}

?>