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 'table.php';
18 require_once 'linetabs.php';
19 require_once 'datepicker.php';
22 ini_set("memory_limit","256M");
25 drupal_set_title('Events');
27 // as per index.php, we get here if _GET['type'] is set
29 $from_date=$_GET['from_date'];
30 $until_date=$_GET['until_date'];
34 //////////////////////////////////////////////////////////// dates
35 // our format is yyyy/MMM/dd
37 // given the user-typed string, return (*) a visible string, (*) an int time
38 // the flag should be false for the 'from' field, and true for the until field
40 $EPOCH="1 January 2008";
43 function parse_date ($user_date,$until_if_true=false,$DAY,$EPOCH) {
46 if (empty ($user_date)) {
47 if ( ! $until_if_true) {
48 // an empty string means the epoch in from-mode
49 $date=$EPOCH; $time=strtotime($date);
51 $date="now"; $time=strtotime($date);
55 // user-provided string
56 list ($year,$month,$day) = split ('[/.-]',$user_date);
57 $date=sprintf("%s %s %s",$day,$month,$year);
58 $time=strtotime($date);
59 //if the flag is set, we add 23h59'59'', so the 'until' date is inclusive
63 $date=strftime("%Y/%b/%d @ %H:%M",$time);
65 return array($date,$time);
68 //////////////////////////////////////////////////////////// layout
69 // outline node ids and person ids with a link
70 function e_node ($node_id) {
71 if (! $node_id) return "";
72 return l_node_t($node_id,$node_id);
74 function e_person ($person_id) {
75 if (! $person_id) return "";
76 return l_person_t($person_id,$person_id);
79 function e_event ($event_id) {
80 if (! $event_id) return "";
81 return href(l_event("Event","event",$event_id),$event_id);
84 function e_subject ($type,$id) {
85 $mess=$type . " " . $id;
87 case 'Node': return l_node_t ($id,$mess);
88 case 'Site': return l_site_t ($id,$mess);
89 case 'Person': return l_person_t ($id,$mess);
90 case 'Slice': return l_slice_t ($id,$mess);
91 case 'Role': case 'Key': case 'PCU': case 'Interface': case 'NodeGroup': case "Address":
93 default: return "Unknown $type" . "-" . $id;
97 // synthesize links to the subject objects from types and ids
98 function e_subjects ($param) {
99 $types=$param['object_types'];
100 $ids=$param['object_ids'];
101 if ( ! $types) return "";
102 return plc_vertical_table(array_map ("e_subject",$types,$ids));
105 function e_issuer ($param) {
106 if ($param['node_id']) return e_subject('Node',$param['node_id']);
107 if ($param['person_id']) return e_subject('Person',$param['person_id']);
111 function e_auth ($event) {
112 if (array_key_exists('auth_type',$event))
113 return $event['auth_type'];
118 function e_fault ($event) {
119 $f=$event['fault_code'];
120 if ($f==0) return "OK";
124 ////////////////////////////////////////////////////////////
125 // for convenience, add 1 day to the 'until' date as otherwise this corresponds to 0:00
128 $tabs['Clear events']=l_events();
129 plekit_linetabs($tabs);
131 list($from_string,$from_time) = parse_date ($from_date,false,$DAY,$EPOCH);
132 list($until_string,$until_time) = parse_date ($until_date,true,$DAY,$EPOCH);
134 if ($from_time > $until_time) {
135 drupal_set_error("Warning - <from> is after <until>");
140 // sort events by time is not good enough, let's use event_id
141 $filter['-SORT']='-event_id';
142 $filter[']time']=$from_time;
143 $filter['[time']=$until_time;
145 //////////////////////////////////////// Events
146 if ($type == 'Event') {
148 // and the filter applied for fetching events using GetEvent
149 $user_desc=$_GET['event'];
150 if ( ! empty($user_desc)) {
151 // should parse stuff like 45-90,230-3000 - some other day
152 $filter['event_id']=intval($user_desc);
155 $events = $api->GetEvents($filter);
156 $title="Events [ $from_string - $until_string] matching " . ($user_desc ? $user_desc : "everything");
158 // see actual display of $title and $events below
164 $primary_key='person_id';
166 $user_input=$_GET['person'];
167 $method="GetPersons";
168 $object_type='Person';
172 $primary_key='node_id';
173 $string_key='hostname';
174 $user_input=$_GET['node'];
180 $primary_key='site_id';
181 $string_key='login_base';
182 $user_input=$_GET['site'];
188 $primary_key='slice_id';
190 $user_input=$_GET['slice'];
192 $object_type='Slice';
197 $title="Events [ $from_string - $until_string]";
198 $title .= " type=$object_type";
200 foreach ( split(",",$user_input) as $user_desc) {
202 if (my_is_int($user_desc)) {
203 $obj_check = call_user_func(array($api,$method),array(intval($user_desc)),array($primary_key));
204 if (empty ($obj_check)) {
205 $messages[] = "No such " . $primary_key . ": " . $user_desc;
207 $object_ids[] = $obj_check[0][$primary_key];
208 $title .= " $user_desc, " ;
212 $new_object_ids=call_user_func (array($api,$method), array($string_key=>$user_desc),array($primary_key,$string_key));
213 if (empty($new_object_ids)) {
214 $messages[] = "No " . $string_key . " matching " . $user_desc;
216 foreach ($new_object_ids as $new_obj_id) {
217 $object_ids[] = $new_obj_id[$primary_key];
218 $title .= $new_obj_id[$primary_key] . ", ";
224 $event_objs = $api->GetEventObjects(array('object_id'=>$object_ids,'object_type'=>$object_type),array('event_id'));
225 // get set of event_ids
226 $event_ids = array_map ( create_function ('$eo','return $eo["event_id"];') , $event_objs);
228 $events = $api->GetEvents (array('event_id'=>$event_ids));
230 // see actual display of $title and $events below
234 drupal_set_title ($title);
236 if (!empty($messages))
237 foreach ($messages as $line)
238 drupal_set_message($line);
240 $headers=array("Id"=>"int",
241 "Time"=>"EnglishDateTime",
244 "Subjects"=>"string",
251 $table = new PlekitTable ("events",$headers,"0r");
252 $table->set_options (array ('max_pages'=>20));
254 foreach ($events as $event) {
257 $message = htmlentities($event['message'], ENT_QUOTES);
258 $call = htmlentities($event['call'], ENT_QUOTES);
259 $text = sprintf("message=<<%s>>\\n\\ncall=<<%s>>\\n\\nruntime=<<%f>>\\n",$message,$call,$event['runtime']);
260 $method = "<input type=button name='call' value='" . $event['call_name'] ."' onclick='alert(\"" . $text . "\")'";
261 // $method = sprintf('<span title="%s">%s</span>',$call,$method);
263 // the message button
264 $trunc_mess=htmlentities(truncate($event['message'],40),ENT_QUOTES);
265 $message="<input type=button name='message' value='" . $trunc_mess ."' onclick='alert(\"" . $text . "\")'";
266 $details="<input type=button name='message' value='X' onclick='alert(\"" . $text . "\")'";
267 // $message=sprintf('<span title="%s">%s</span>',$message,$message);
269 $message=truncate($event['message'],40);
271 $table->cell(e_event($event['event_id']));
272 $table->cell(date('M/d/Y H:i', $event['time']));
273 $table->cell($event['call_name']);
274 $table->cell($message);
275 $table->cell(e_subjects($event));
276 $table->cell(e_issuer($event));
277 $table->cell(e_auth($event));
278 $table->cell(e_fault($event));
279 $table->cell($details);
282 $table->set_options(array('notes'=>array("The R column shows the call result value, a.k.a. fault_code",
283 "Click the button in the D(etails) column to get more details")));
286 //plekit_linetabs ($tabs,"bottom");
289 include 'plc_footer.php';