import time
from datetime import datetime

def my_log_parser(logger, line):
    if line.count(',') >= 6:
        date, report_type, group_id, job_id, event, package, rest = line.split(',',6)

    if report_type == 'J' and event != 'Pending':
        date = datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
        date = time.mktime(date.timetuple())
        url = '${bldr_url}/#/pkgs/{0}/builds/{1}'.format(package, job_id)

        if event == 'Failed':
            error = rest.split(',')[-1]
            message = package + ' ' + error + ' ' + url
        elif event == 'Complete':
            message = package + ' ' + url
        else:
            message = package

        logged_event = {
            'msg_title': event,
            'timestamp': date,
            'msg_text': message,
            'priority': 'normal',
            'event_type': report_type,
            'aggregation_key': group_id,
            'alert_type': 'info'
        }
        return logged_event

    return None

import time
from datetime import datetime

def my_log_parser(logger, line):
    if line.count(',') >= 6:
        date, report_type, group_id, job_id, event, package, rest = line.split(',',6)

        if report_type == 'J' and event != 'Pending':
            date = datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
            date = time.mktime(date.timetuple())
            url = '${bldr_url}/#/pkgs/{0}/builds/{1}'.format(package, job_id)

            if event == 'Failed':
                error = rest.split(',')[-1]
                message = package + ' ' + error + ' ' + url
            elif event == 'Complete':
                message = package + ' ' + url
            else:
                message = package

            logged_event = {
                'msg_title': event,
                'timestamp': date,
                'msg_text': message,
                'priority': 'normal',
                'event_type': report_type,
                'aggregation_key': group_id,
                'alert_type': 'info'
            }
            return logged_event

    return None

Fix dashboard script parsing failure
Fix dashboard script parsing failure

Signed-off-by: Salim Alam <18ae4dd1e3db1d49a738226169e3b099325c79a0@chef.io>

  import time
  from datetime import datetime
  
  def my_log_parser(logger, line):
      if line.count(',') >= 6:
          date, report_type, group_id, job_id, event, package, rest = line.split(',',6)
  
-     if report_type == 'J' and event != 'Pending':
+         if report_type == 'J' and event != 'Pending':
-         date = datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
+             date = datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
-         date = time.mktime(date.timetuple())
+             date = time.mktime(date.timetuple())
-         url = '${bldr_url}/#/pkgs/{0}/builds/{1}'.format(package, job_id)
+             url = '${bldr_url}/#/pkgs/{0}/builds/{1}'.format(package, job_id)
  
-         if event == 'Failed':
+             if event == 'Failed':
-             error = rest.split(',')[-1]
+                 error = rest.split(',')[-1]
-             message = package + ' ' + error + ' ' + url
+                 message = package + ' ' + error + ' ' + url
-         elif event == 'Complete':
+             elif event == 'Complete':
-             message = package + ' ' + url
+                 message = package + ' ' + url
-         else:
+             else:
-             message = package
+                 message = package
  
-         logged_event = {
+             logged_event = {
-             'msg_title': event,
+                 'msg_title': event,
-             'timestamp': date,
+                 'timestamp': date,
-             'msg_text': message,
+                 'msg_text': message,
-             'priority': 'normal',
+                 'priority': 'normal',
-             'event_type': report_type,
+                 'event_type': report_type,
-             'aggregation_key': group_id,
+                 'aggregation_key': group_id,
-             'alert_type': 'info'
+                 'alert_type': 'info'
-         }
+             }
-         return logged_event
+             return logged_event
  
      return None
  
Fix dashboard script parsing failure
## Code Before:
import time
from datetime import datetime

def my_log_parser(logger, line):
    if line.count(',') >= 6:
        date, report_type, group_id, job_id, event, package, rest = line.split(',',6)

    if report_type == 'J' and event != 'Pending':
        date = datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
        date = time.mktime(date.timetuple())
        url = '${bldr_url}/#/pkgs/{0}/builds/{1}'.format(package, job_id)

        if event == 'Failed':
            error = rest.split(',')[-1]
            message = package + ' ' + error + ' ' + url
        elif event == 'Complete':
            message = package + ' ' + url
        else:
            message = package

        logged_event = {
            'msg_title': event,
            'timestamp': date,
            'msg_text': message,
            'priority': 'normal',
            'event_type': report_type,
            'aggregation_key': group_id,
            'alert_type': 'info'
        }
        return logged_event

    return None

## Instruction:
Fix dashboard script parsing failure
## Code After:
import time
from datetime import datetime

def my_log_parser(logger, line):
    if line.count(',') >= 6:
        date, report_type, group_id, job_id, event, package, rest = line.split(',',6)

        if report_type == 'J' and event != 'Pending':
            date = datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
            date = time.mktime(date.timetuple())
            url = '${bldr_url}/#/pkgs/{0}/builds/{1}'.format(package, job_id)

            if event == 'Failed':
                error = rest.split(',')[-1]
                message = package + ' ' + error + ' ' + url
            elif event == 'Complete':
                message = package + ' ' + url
            else:
                message = package

            logged_event = {
                'msg_title': event,
                'timestamp': date,
                'msg_text': message,
                'priority': 'normal',
                'event_type': report_type,
                'aggregation_key': group_id,
                'alert_type': 'info'
            }
            return logged_event

    return None
