5 require_once 'plc_login.php';
7 // Get session and API handles
8 require_once 'plc_session.php';
12 require_once 'plc_drupal.php';
13 include 'plc_header.php';
16 require_once 'plc_functions.php';
17 require_once 'plc_tables.php';
18 require_once 'plc_minitabs.php';
19 require_once 'plc_datepicker.php';
22 ini_set("memory_limit","256M");
25 drupal_set_title('Events');
32 //////////////////////////////////////////////////////////// form
34 // defaults for day ('j'), 3-letter month ('M') or year ('Y')
35 function the_date ($key,$dateformat) {
36 if ($_GET[$key]) return $_GET[$key];
37 else return date($dateformat);
40 // fill out dates from now if not specified
41 $from_picker = new PlcDatepicker ('from_date','From (inclusive)');
42 $from_picker->today();
43 $from_html=$from_picker->html();
44 $until_picker = new PlcDatepicker ('until_date','Until (inclusive)');
45 $until_picker->today();
46 $until_html=$until_picker->html();
51 <form method=get name='events' action='$action' >
53 <table class='plc_details'>
56 <input type='radio' name='type' id='events' value='Event' checked='checked'> Events:
58 <input type='text' onSelect="submit();" onFocus='events.checked=true' name='event' size=20>
60 <input type='radio' name='type' id='persons' value='Person'> Persons:
62 <input type='text' onSelect="submit();" onFocus='persons.checked=true' name='person' size=20>
64 <input type='radio' name='type' id='nodes' value='Node'> Nodes:
66 <input type='text' onSelect="submit();" onFocus='nodes.checked=true' name='node' size=20>
68 <input type='radio' name='type' id='sites' value='Site'> Sites:
70 <input type='text' onSelect="submit();" onFocus='sites.checked=true' name='site' size=20>
72 <input type='radio' name='type' id='slices' value='Slice'> Slices:
74 <input type='text' onSelect="submit();" onFocus='slices.checked=true' name='slice' size=20>
78 <tr><td> $from_html </td><td>$until_html</td></tr>
79 <tr><td colspan=2>  </td></tr>
80 <TR><TD colspan=2 style='text-align:center'>
81 <input type='submit' align='middle' value='Show Events'>
88 //////////////////////////////////////////////////////////// dates
89 // our format is yyyy/MMM/dd
90 function parse_date ($datestring) {
91 if (empty ($datestring)) {
92 $year="2008"; $month="Jan"; $day="01";
94 list ($year,$month,$day) = split ('[/.-]',$datestring);
96 $date=sprintf("%s %s %s",$day,$month,$year);
97 $time=strtotime($date);
98 return array($date,$time);
101 function parse_dates () {
102 list($from_date,$from_time) = parse_date($_GET['from_date']);
103 list($until_date,$until_time) = parse_date($_GET['until_date']);
104 return array($from_date,$from_time,$until_date,$until_time);
107 //////////////////////////////////////////////////////////// layout
108 // outline node ids and person ids with a link
109 function e_node ($node_id) {
110 if (! $node_id) return "";
111 return l_node_t($node_id,$node_id);
113 function e_person ($person_id) {
114 if (! $person_id) return "";
115 return l_person_t($person_id,$person_id);
118 function e_event ($event_id) {
119 if (! $event_id) return "";
120 return href(l_event("Event","event",$event_id),$event_id);
123 function e_subject ($type,$id) {
124 $mess=$type . " " . $id;
126 case 'Node': return l_node_t ($id,$mess);
127 case 'Site': return l_site_t ($id,$mess);
128 case 'Person': return l_person_t ($id,$mess);
129 case 'Slice': return l_slice_t ($id,$mess);
130 case 'Role': case 'Key': case 'PCU': case 'Interface': case 'NodeGroup': case "Address":
132 default: return "Unknown $type" . "-" . $id;
136 // synthesize links to the subject objects from types and ids
137 function e_subjects ($param) {
138 $types=$param['object_types'];
139 $ids=$param['object_ids'];
140 if ( ! $types) return "";
141 return plc_vertical_table(array_map ("e_subject",$types,$ids));
144 function e_issuer ($param) {
145 if ($param['node_id']) return e_subject('Node',$param['node_id']);
146 if ($param['person_id']) return e_subject('Person',$param['person_id']);
150 function e_auth ($event) {
151 if (array_key_exists('auth_type',$event))
152 return $event['auth_type'];
157 function e_fault ($event) {
158 $f=$event['fault_code'];
159 if ($f==0) return "OK";
163 ////////////////////////////////////////////////////////////
164 // for convenience, add 1 day to the 'until' date as otherwise this corresponds to 0:00
167 if ( ! plc_is_admin()) {
168 plc_warning("You need admin role to see this page.");
170 } else if (! $_GET['type']) {
171 echo "<h2>Select the events to focus on :</h2>";
172 // print the selection frame
178 $tabs['Back to events form']=l_events();
182 list($from_date,$from_time,$until_date,$until_time) = parse_dates ();
183 // add one day to until_time - otherwise this corresponds to 0:0
184 $until_time += $STEP;
185 if ( ($from_time != 0) && ($until_time != $STEP) && ($from_time > $until_time) ) {
186 $messages[] = "Warning - <from> is after <until>";
190 // sort events by time is not good enough, let's use event_id
191 $filter['-SORT']='-event_id';
192 if ($from_time != 0) {
193 $filter[']time']=$from_time;
195 if ($until_time != $STEP) {
196 $filter['[time']=$until_time;
199 //////////////////////////////////////// Events
201 if ($type == 'Event') {
203 // and the filter applied for fetching events using GetEvent
204 $user_desc=$_GET['event'];
205 if ( ! empty($user_desc)) {
206 // should parse stuff like 45-90,230-3000 - some other day
207 $filter['event_id']=intval($user_desc);
209 // the filter might be void here - in python we need an empty dict but that's not what we get so
210 if (empty($filter)) {
213 $events = $api->GetEvents($filter);
214 $title="Events matching " . ($user_desc ? $user_desc : "everything");
216 $title .= " From " . $from_date;
217 if ($until_time != $STEP)
218 $title .= " Until " . $until_date;
220 // see actual display of $title and $events below
226 $primary_key='person_id';
228 $user_input=$_GET['person'];
229 $method="GetPersons";
230 $object_type='Person';
234 $primary_key='node_id';
235 $string_key='hostname';
236 $user_input=$_GET['node'];
242 $primary_key='site_id';
243 $string_key='login_base';
244 $user_input=$_GET['site'];
250 $primary_key='slice_id';
252 $user_input=$_GET['slice'];
254 $object_type='Slice';
259 $title=sprintf('Events for type %s:',$object_type);
260 foreach ( split(",",$user_input) as $user_desc) {
262 if (my_is_int($user_desc)) {
263 $obj_check = call_user_func(array($api,$method),array(intval($user_desc)),array($primary_key));
264 if (empty ($obj_check)) {
265 $messages[] = "No such " . $primary_key . ": " . $user_desc;
267 $object_ids[] = $obj_check[0][$primary_key];
268 $title .= $user_desc . ", " ;
272 $new_object_ids=call_user_func (array($api,$method), array($string_key=>$user_desc),array($primary_key,$string_key));
273 if (empty($new_object_ids)) {
274 $messages[] = "No " . $string_key . " matching " . $user_desc;
276 foreach ($new_object_ids as $new_obj_id) {
277 $object_ids[] = $new_obj_id[$primary_key];
278 $title .= $new_obj_id[$primary_key] . ", ";
284 $event_objs = $api->GetEventObjects(array('object_id'=>$object_ids,'object_type'=>$object_type),array('event_id'));
285 // get set of event_ids
286 $event_ids = array_map ( create_function ('$eo','return $eo["event_id"];') , $event_objs);
288 $events = $api->GetEvents (array('event_id'=>$event_ids));
290 // see actual display of $title and $events below
294 drupal_set_title ($title);
296 if (!empty($messages))
297 foreach ($messages as $line)
298 drupal_set_message($line);
300 $headers=array("Id"=>"int",
301 "Time"=>"EnglishDateTime",
304 "Subjects"=>"string",
311 $table = new PlcTable ("events",$headers,"0r");
312 $table->set_options (array ('max_pages'=>20));
314 foreach ($events as $event) {
317 $message = htmlentities($event['message'], ENT_QUOTES);
318 $call = htmlentities($event['call'], ENT_QUOTES);
319 $text = sprintf("message=<<%s>>\\n\\ncall=<<%s>>\\n\\nruntime=<<%f>>\\n",$message,$call,$event['runtime']);
320 $method = "<input type=button name='call' value='" . $event['call_name'] ."' onclick='alert(\"" . $text . "\")'";
321 // $method = sprintf('<span title="%s">%s</span>',$call,$method);
323 // the message button
324 $trunc_mess=htmlentities(truncate($event['message'],40),ENT_QUOTES);
325 $message="<input type=button name='message' value='" . $trunc_mess ."' onclick='alert(\"" . $text . "\")'";
326 $details="<input type=button name='message' value='X' onclick='alert(\"" . $text . "\")'";
327 // $message=sprintf('<span title="%s">%s</span>',$message,$message);
329 $message=truncate($event['message'],40);
331 $table->cell(e_event($event['event_id']));
332 $table->cell(date('M/d/Y H:i', $event['time']));
333 $table->cell($event['call_name']);
334 $table->cell($message);
335 $table->cell(e_subjects($event));
336 $table->cell(e_issuer($event));
337 $table->cell(e_auth($event));
338 $table->cell(e_fault($event));
339 $table->cell($details);
342 $table->set_options(array('notes'=>array("The R column shows the call result value, a.k.a. fault_code",
343 "Click the button in the D(etails) column to get more details")));
350 include 'plc_footer.php';