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) = preg_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 'Interface': return l_interface_t ($id, $mess);
92 case 'Role': case 'Key': case 'PCU': case 'NodeGroup': case "Address":
94 default: return "Unknown $type" . "-" . $id;
98 // synthesize links to the subject objects from types and ids
99 function e_subjects ($param) {
100 $types=$param['object_types'];
101 $ids=$param['object_ids'];
102 if ( ! $types) return "";
103 return plc_vertical_table(array_map ("e_subject",$types,$ids));
106 function e_issuer ($param) {
107 if ($param['node_id']) return e_subject('Node',$param['node_id']);
108 if ($param['person_id']) return e_subject('Person',$param['person_id']);
112 function e_auth ($event) {
113 if (array_key_exists('auth_type',$event))
114 return $event['auth_type'];
119 function e_fault ($event) {
120 $f=$event['fault_code'];
121 if ($f==0) return "OK";
125 ////////////////////////////////////////////////////////////
126 // for convenience, add 1 day to the 'until' date as otherwise this corresponds to 0:00
129 $tabs['Clear events']=l_events();
130 plekit_linetabs($tabs);
132 list($from_string,$from_time) = parse_date ($from_date,false,$DAY,$EPOCH);
133 list($until_string,$until_time) = parse_date ($until_date,true,$DAY,$EPOCH);
135 if ($from_time > $until_time) {
136 drupal_set_error("Warning - <from> is after <until>");
141 // sort events by time is not good enough, let's use event_id
142 $filter['-SORT']='-event_id';
143 $filter[']time']=$from_time;
144 $filter['[time']=$until_time;
146 //////////////////////////////////////// Events
147 if ($type == 'Event') {
149 // and the filter applied for fetching events using GetEvent
150 $user_desc=$_GET['event'];
151 if ( ! empty($user_desc)) {
152 // should parse stuff like 45-90,230-3000 - some other day
153 $filter['event_id']=intval($user_desc);
156 $events = $api->GetEvents($filter);
157 $title="Events [ $from_string - $until_string] matching " . ($user_desc ? $user_desc : "everything");
159 // see actual display of $title and $events below
165 $primary_key='person_id';
167 $user_input=$_GET['person'];
168 $method="GetPersons";
169 $object_type='Person';
173 $primary_key='node_id';
174 $string_key='hostname';
175 $user_input=$_GET['node'];
181 $primary_key='site_id';
182 $string_key='login_base';
183 $user_input=$_GET['site'];
189 $primary_key='slice_id';
191 $user_input=$_GET['slice'];
193 $object_type='Slice';
198 $title="Events [ $from_string - $until_string]";
199 $title .= " type=$object_type";
201 foreach ( explode(",",$user_input) as $user_desc) {
203 if (my_is_int($user_desc)) {
204 $obj_check = call_user_func(array($api,$method),array(intval($user_desc)),array($primary_key));
205 if (empty ($obj_check)) {
206 $messages[] = "No such " . $primary_key . ": " . $user_desc;
208 $object_ids[] = $obj_check[0][$primary_key];
209 $title .= " $user_desc, " ;
213 $new_object_ids=call_user_func (array($api,$method), array($string_key=>$user_desc),array($primary_key,$string_key));
214 if (empty($new_object_ids)) {
215 $messages[] = "No " . $string_key . " matching " . $user_desc;
217 foreach ($new_object_ids as $new_obj_id) {
218 $object_ids[] = $new_obj_id[$primary_key];
219 $title .= $new_obj_id[$primary_key] . ", ";
225 $event_objs = $api->GetEventObjects(array('object_id'=>$object_ids,'object_type'=>$object_type),array('event_id'));
226 // get set of event_ids
227 $event_ids = array_map (function ($eo) {return $eo["event_id"];} , $event_objs);
229 $events = $api->GetEvents (array('event_id'=>$event_ids));
231 // see actual display of $title and $events below
235 drupal_set_title ($title);
237 if (!empty($messages))
238 foreach ($messages as $line)
239 drupal_set_message($line);
241 $headers=array("Id"=>"int",
242 "Time"=>"EnglishDateTime",
245 "Subjects"=>"string",
252 $table = new PlekitTable ("events",$headers,"0r");
253 $table->set_options (array ('max_pages'=>20));
255 foreach ($events as $event) {
258 $message = htmlentities($event['message'], ENT_QUOTES);
259 $call = htmlentities($event['call'], ENT_QUOTES);
260 $text = sprintf("message=<<%s>>\\n\\ncall=<<%s>>\\n\\nruntime=<<%f>>\\n",$message,$call,$event['runtime']);
261 $method = "<input type=button name='call' value='" . $event['call_name'] ."' onclick='alert(\"" . $text . "\")'";
262 // $method = sprintf('<span title="%s">%s</span>',$call,$method);
264 // the message button
265 $trunc_mess=htmlentities(truncate($event['message'],40),ENT_QUOTES);
266 $message="<input type=button name='message' value='" . $trunc_mess ."' onclick='alert(\"" . $text . "\")'";
267 $details="<input type=button name='message' value='+' onclick='alert(\"" . $text . "\")'";
268 // $message=sprintf('<span title="%s">%s</span>',$message,$message);
270 $message=truncate($event['message'],40);
272 $table->cell(e_event($event['event_id']));
273 $table->cell(date('M/d/Y H:i', $event['time']));
274 $table->cell($event['call_name']);
275 $table->cell($message);
276 $table->cell(e_subjects($event));
277 $table->cell(e_issuer($event));
278 $table->cell(e_auth($event));
279 $table->cell(e_fault($event));
280 $table->cell($details);
283 $table->set_options(array('notes'=>array("The R column shows the call result value, a.k.a. fault_code",
284 "Click the button in the D(etails) column to get more details")));
287 //plekit_linetabs ($tabs,"bottom");
290 include 'plc_footer.php';