Beispiel #1
0
def view_log(request):
  return_dict = {}
  try:
    form = log_management_forms.ViewLogsForm(request.POST or None)
    if request.method == 'POST':
      if form.is_valid():
        cd = form.cleaned_data
        log_type = cd['log_type']
        if log_type not in ['alerts', 'audit', 'hardware', 'av']:
          raise Exception('Invalid log type specified')
        if log_type == 'alerts':
          alerts_list, err = alerts.load_alerts()
          if err:
            raise Exception(err)
          return_dict['alerts_list'] = alerts_list
          return django.shortcuts.render_to_response('view_alerts.html', return_dict, context_instance=django.template.context.RequestContext(request))
        elif log_type == 'audit':
          al, err = audit.get_lines()
          if err:
            raise Exception(err)
          return_dict["audit_list"] = al
          return django.shortcuts.render_to_response('view_audit_trail.html', return_dict, context_instance=django.template.context.RequestContext(request))
        elif log_type == 'av':
          vs_log_list,err = clamav.get_virus_scan_log()
          if err:
            raise Exception(err)
          return_dict['vs_log_list'] = vs_log_list
          return django.shortcuts.render_to_response('view_virus_scan_logs.html', return_dict, context_instance=django.template.context.RequestContext(request))
        
        elif log_type == 'hardware':
          hw_platform, err = common.get_hardware_platform()
          if err:
            raise Exception(err)
          if not hw_platform or hw_platform != 'dell':
            raise Exception('Unknown hardware platform')
          return_dict['hw_platform'] = hw_platform
          if hw_platform == 'dell':
            from integralstor_common.platforms import dell
            logs_dict, err = dell.get_alert_logs()
            if logs_dict:
              return_dict['logs_dict'] = logs_dict
          return django.shortcuts.render_to_response('view_hardware_logs.html', return_dict, context_instance=django.template.context.RequestContext(request))
    # either a get or an invalid form so send back form
    return_dict['form'] = form
    return django.shortcuts.render_to_response('view_log_form.html', return_dict, context_instance=django.template.context.RequestContext(request))
  except Exception, e:
    return_dict['base_template'] = "logging_base.html"
    return_dict["page_title"] = 'System alerts'
    return_dict['tab'] = 'view_current_alerts_tab'
    return_dict["error"] = 'Error loading system alerts'
    return_dict["error_details"] = str(e)
    return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
Beispiel #2
0
def view_audit_trail(request):
  return_dict = {}
  try:
    al = None
    al, err = audit.get_lines()
    if err:
      raise Exception(err)
    return_dict["audit_list"] = al
    return django.shortcuts.render_to_response('view_audit_trail.html', return_dict, context_instance=django.template.context.RequestContext(request))
  except Exception, e:
    return_dict['base_template'] = "logging_base.html"
    return_dict["page_title"] = 'System audit trail'
    return_dict['tab'] = 'view_current_audit_tab'
    return_dict["error"] = 'Error loading system audit trail'
    return_dict["error_details"] = str(e)
    return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def view_rotated_log_file(request, log_type):

  return_dict = {}
  try:
    return_dict['tab'] = 'view_rotated_alert_log_list_tab'
    if log_type not in ["alerts", "audit_trail"]:
      raise Exception("Unknown log type")
  
    if request.method != "POST":
      raise Exception("Unsupported request")
      
    if "file_name" not in request.POST:
      raise Exception("Filename not specified")
  
    file_name = request.POST["file_name"]
  
    return_dict["historical"] = True
    if log_type == "alerts":
      return_dict['tab'] = 'view_rotated_alert_log_list_tab'
      l, err = alerts.load_alerts(file_name)
      if err:
        raise Exception(err)
      return_dict["alerts_list"] = l
      return django.shortcuts.render_to_response('view_alerts.html', return_dict, context_instance = django.template.context.RequestContext(request))
    else:
      return_dict['tab'] = 'view_rotated_audit_log_list_tab'
      d, err = audit.get_lines(file_name)
      if err:
        raise Exception(err)
      return_dict["audit_list"] = d
      return django.shortcuts.render_to_response('view_audit_trail.html', return_dict, context_instance = django.template.context.RequestContext(request))
  except Exception, e:
    return_dict['base_template'] = "logging_base.html"
    return_dict["page_title"] = 'View rotated log file'
    return_dict["error"] = 'Error viewing rotated log file'
    return_dict["error_details"] = str(e)
    return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
Beispiel #4
0
def view_rotated_log_file(request, log_type):

  return_dict = {}
  try:
    return_dict['tab'] = 'view_rotated_alert_log_list_tab'
    if log_type not in ["alerts", "audit_trail"]:
      raise Exception("Unknown log type")
  
    if request.method != "POST":
      raise Exception("Unsupported request")
      
    if "file_name" not in request.POST:
      raise Exception("Filename not specified")
  
    file_name = request.POST["file_name"]
  
    return_dict["historical"] = True
    if log_type == "alerts":
      return_dict['tab'] = 'view_rotated_alert_log_list_tab'
      l, err = alerts.load_alerts(file_name)
      if err:
        raise Exception(err)
      return_dict["alerts_list"] = l
      return django.shortcuts.render_to_response('view_alerts.html', return_dict, context_instance = django.template.context.RequestContext(request))
    else:
      return_dict['tab'] = 'view_rotated_audit_log_list_tab'
      d, err = audit.get_lines(file_name)
      if err:
        raise Exception(err)
      return_dict["audit_list"] = d
      return django.shortcuts.render_to_response('view_audit_trail.html', return_dict, context_instance = django.template.context.RequestContext(request))
  except Exception, e:
    return_dict['base_template'] = "logging_base.html"
    return_dict["page_title"] = 'View rotated log file'
    return_dict["error"] = 'Error viewing rotated log file'
    return_dict["error_details"] = str(e)
    return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
        if "saved" in request.REQUEST:
          return_dict["saved"] = request.REQUEST["saved"]
        if "not_saved" in request.REQUEST:
          return_dict["not_saved"] = request.REQUEST["not_saved"]
        if "err" in request.REQUEST:
          return_dict["err"] = request.REQUEST["err"]
        template = "view_email_settings.html"
      except Exception, e:
        iv_logging.debug("error loading email settings %s"%e)
        return_dict["error"] = str(e)

    elif page == "audit_trail":

      al = None
      try:
        al = audit.get_lines()
      except Exception, e:
        return_dict["error"] = str(e)
      else:
        template = "view_audit_trail.html"
        return_dict["audit_list"] = al

    elif page == "node_status":
      
      template = "view_node_status.html"
      if "from" in request.GET:
        frm = request.GET["from"]
        return_dict['frm'] = frm
      sorted_disks = []
      for key,value in sorted(si[info]["disks"].iteritems(), key=lambda (k,v):v["position"]):
        sorted_disks.append(key)
        return_dict["saved"] = request.REQUEST["saved"]
      if "not_saved" in request.REQUEST:
        return_dict["not_saved"] = request.REQUEST["not_saved"]
      if "err" in request.REQUEST:
        return_dict["err"] = request.REQUEST["err"]
      template = "view_email_settings.html"

    elif page == "audit_trail":
 
      return_dict['base_template'] = "logging_base.html"
      return_dict["page_title"] = 'System audit trail'
      return_dict['tab'] = 'view_current_audit_tab'
      return_dict["error"] = 'Error loading system audit trail'
      al = None
      template = "view_audit_trail.html"
      al, err = audit.get_lines()
      if err:
        raise Exception(err)
      return_dict["audit_list"] = al

    elif page == "node_info":
      return_dict['base_template'] = "system_base.html"
      return_dict["page_title"] = 'System configuration'
      return_dict['tab'] = 'node_info_tab'
      return_dict["error"] = 'Error loading system configuration'
      template = "view_node_info.html"
      if "from" in request.GET:
        frm = request.GET["from"]
        return_dict['frm'] = frm
      #return_dict['node'] = si[info]
      return_dict['node'] = si[si.keys()[0]]
Beispiel #7
0
def download_log(request):
  """ Download the system log of the type specified in log_type POST param 
  This calls the /sys_log via an http request on that node to get the info"""

  return_dict = {}
  try:
    form = log_management_forms.DownloadLogsForm(request.POST or None)
  
    if request.method == 'POST':
      if form.is_valid():
        cd = form.cleaned_data
        log_type = cd['log_type']
  
        response = django.http.HttpResponse()
        if log_type in ['alerts', 'audit', 'hardware']:
          if log_type == 'alerts':
            response['Content-disposition'] = 'attachment; filename=alerts_log.txt'
            all_alerts, err = alerts.load_alerts()
            if err:
              raise Exception(err)
            for alert in all_alerts:
              response.write('%s : %s\n'%(alert['time'], alert['message']))
              response.flush()
          elif log_type == 'audit':
            response['Content-disposition'] = 'attachment; filename=audit_log.txt'
            all_audits, err = audit.get_lines()
            if err:
              raise Exception(err)
            for audit_info in all_audits:
              response.write('Time : %s \n'%audit_info['time'])
              response.write('Source IP : %s \n'%audit_info['ip'])
              response.write('Action : %s \n'%audit_info['action'])
              response.write('\n')
              response.flush()
          elif log_type == 'hardware':
            response['Content-disposition'] = 'attachment; filename=hardware_logs.txt'
            hw_platform, err = common.get_hardware_platform()
            if not hw_platform or hw_platform != 'dell':
              raise Exception('Unknown hardware platform')
            if hw_platform == 'dell':
              from integralstor_common.platforms import dell
              logs_dict, err = dell.get_alert_logs()
              if err:
                raise Exception(err)
              if not logs_dict:
                raise Exception('No logs detected!')
              for timestamp, log_list in logs_dict.items():
                for log in log_list:
                  response.write('Time : %s\n'%log['date_time'])
                  response.write('Severity : %s\n'%log['Severity'])
                  response.write('Description : %s\n'%log['description'])
                  response.write('\n')
                  response.flush()
            else:
              raise Exception('Unknown platform')
        else:
  
            fn = {'boot':'/var/log/boot.log', 'dmesg':'/var/log/dmesg', 'message':'/var/log/messages', 'smb':'/var/log/smblog.vfs', 'winbind':'/var/log/samba/log.winbindd','ctdb':'/var/log/log.ctdb'}
            dn = {'boot':'boot.log', 'dmesg':'dmesg', 'message':'messages','smb':'samba_logs','winbind':'winbind_logs','ctdb':'ctdb_logs'}
  
            file_name = fn[log_type]
            display_name = dn[log_type]
  
            zf_name = '%s.zip'%display_name
      
            try:
              zf = zipfile.ZipFile(zf_name, 'w')
              zf.write(file_name, arcname = display_name)
              zf.close()
            except Exception as e:
              raise Exception("Error compressing remote log file : %s"%str(e))
  
            response['Content-disposition'] = 'attachment; filename=%s.zip'%(display_name)
            response['Content-type'] = 'application/x-compressed'
            with open(zf_name, 'rb') as f:
              byte = f.read(1)
              while byte:
                response.write(byte)
                byte = f.read(1)
            response.flush()
  
        return response
  
    # either a get or an invalid form so send back form
    return_dict['form'] = form
    return django.shortcuts.render_to_response('download_log_form.html', return_dict, context_instance=django.template.context.RequestContext(request))
  except Exception, e:
    return_dict['base_template'] = "logging_base.html"
    return_dict["page_title"] = 'Download system logs'
    return_dict['tab'] = 'download_logs_tab'
    return_dict["error"] = 'Error downloading system logs'
    return_dict["error_details"] = str(e)
    return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
      return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance = django.template.context.RequestContext(request))
  
    file_name = request.POST["file_name"]
  
    if log_type == "alerts":
      try:
        l = alerts.load_alerts(file_name)
        return_dict["alerts_list"] = l
        return_dict["historical"] = True
        return django.shortcuts.render_to_response('view_alerts.html', return_dict, context_instance = django.template.context.RequestContext(request))
      except Exception, e:
        return_dict["error"] = str(e)
        return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance = django.template.context.RequestContext(request))
    else:
      try:
        d = audit.get_lines(file_name)
        return_dict["audit_list"] = d
        return_dict["historical"] = True
        return django.shortcuts.render_to_response('view_audit_trail.html', return_dict, context_instance = django.template.context.RequestContext(request))
      except Exception, e:
        return_dict["error"] = str(e)
        return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance = django.template.context.RequestContext(request))
  except Exception, e:
    s = str(e)
    if "Another transaction is in progress".lower() in s.lower():
      return_dict["error"] = "An underlying storage operation has locked a volume so we are unable to process this request. Please try after a couple of seconds"
    else:
      return_dict["error"] = "An error occurred when processing your request : %s"%s
    return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))