BEGIN {
OFS = ","
HOUR = 0 
log_date = 0 
datehour = ""
new_datehour = ""
errors = 0   
warnings = 0  
info = 0   
debug = 0   
server_start =0  
worker_start =0  
workers_killed = 0 
has_not_responded = 0
full_vc_refreshes_started = 0
full_vc_refreshes_ended = 0
max_VC_refresh_time = 0
ems_refresh = 0
db_errors = 0
refresh_timeouts = 0
workermonitor_starts = 0
vm_collections = 0
gt_600 = 0
events_caught = 0
events_queued = 0
VC_ID = ""
vcid_last_refresh_started = ""
print "datehour,errors,warnings,info,debug,server stats,worker monitor starts,worker starts,workers killed,has not responded count,ems refresh completed,full VC refresh started,full VC refresh completed,max VC refresh duration,VC id,db errors,refresh timeouts,vmid of last VC refresh started,C&U VM collection count,C&U Wait > 600 seconds,events caught,events queued"
  }
$1 !~ /\[\-\-\-\-\]/ {next}
$2  ~ /E,/ {errors++ }
$2  ~ /W,/ {warnings++}
$2  ~ /I,/ {info++ }
$2  ~ /D,/ {debug++}
$3  ~ /(.*?)T(.*)/ {  #print $0
          datehour_array_count = split($3,date_array,":")
         # print date_array[1] 
          new_datehour = date_array[1]
            if (new_datehour != datehour) { #print "new datehour value is '" datehour "'" 
            old_datehour = datehour
            datehour = new_datehour
            datehour_display = substr(old_datehour,7,2) "/" substr(old_datehour,10,2) "/" substr(old_datehour,2,4) " " substr(old_datehour,13,3) ":00:00" ; # print datehour_display
            if ( length(datehour_display) > 12) {   # don't print the initial value since it is malformed and does not represent anything anyway
            print datehour_display, errors, warnings,info, debug,  server_start,workermonitor_starts,worker_start,workers_killed,has_not_responded,ems_refresh,full_vc_refreshes_started,full_vc_refreshes_ended,max_VC_refresh_time,VC_id,db errors,refresh_timeouts,vcid_last_refresh_started,vm_collections,gt_600,events_caught,events_queued
            datehour = new_datehour  
            errors = 0   
            warnings = 0  
            info = 0   
            debug = 0   
            server_start =0  
            worker_start =0  
            workers_killed = 0 
            has_not_responded = 0
            full_vc_refreshes_started = 0
            full_vc_refreshes_ended = 0
            ems_refresh = 0    
            max_VC_refresh_time    = 0   
            db_errors = 0   
            refresh_timeouts = 0 
            workermonitor_starts = 0    
            vm_collections = 0
            gt_600 = 0
            VC_id = ""
            events_caught = 0
            events_queued = 0
            vcid_last_refresh_started = ""
         #print new_datehour
                         }        
                                           }
                      }
/Caught event/ {events_caught++}
/Queueing event/ {events_queued++}                      
/\[VMDB\]/ {server_start++}
/abstract_adapter/ {db_errors++}
/execution expired  Method\:\[refresh\]/ {refresh_timeouts++
                                              }
/started\./ {worker_start++}
/being killed/ {workers_killed++}
/has not responded/ {has_not_responded++}
/Refreshing targets for EMS: (.*?)\.\.\.Complete/ {ems_refresh++}
/MIQ\(VcRefresher\.refresh\) EMS\:(.*?)ExtManagementSystem(.*?)\.\.\.$/ {full_vc_refreshes_started++
                                                             _temp = split($(NF),vcid_array,".")
                                                             vcid_last_refresh_started = vcid_array[1]
                                                             #add code to delete entire array   
                                                             vcid_array[1] = ""
                                                             }
/Refreshing target ExtManagementSystem (.*?)\.\.\.Completed/ {full_vc_refreshes_ended++
          refresh_time = $(NF-1) # GET REFRESH TIME IN SECONDS
          if (max_VC_refresh_time < refresh_time) {
                                                   max_VC_refresh_time = refresh_time
                                                   _count = split($(NF-3),vcid_array,".")        # split out the vc id by getting first part isolated
                                                   VC_id = vcid_array[1]
                                                   #add code to delete entire array
                                                   vcid_array[1] = ""
                                                   }
          refresh_time = 0
 } 
 /WorkerMonitor started\./ {workermonitor_starts++}
 /\[Vm\.perf_capture\]/  { if ($8 == "MIQ(MiqQueue.get)") { 
                                  vm_collections++
                                  wait_time = int(substr($(NF-1),2,length($(NF-1))-2))
                                  if (wait_time > 600)    
                                      {gt_600++; 
                                      # print $3,wait_time  # suspent printing this for now
                                      }
                                                          }
                          }


END {OFS = ","
            print datehour_display, errors, warnings,info, debug,  server_start,workermonitor_starts,worker_start,workers_killed,has_not_responded,ems_refresh,full_vc_refreshes_started,full_vc_refreshes_ended,max_VC_refresh_time,VC_id,db errors,refresh_timeouts,vcid_last_refresh_started,vm_collections,gt_600,events_caught,events_queued
    }