コード例 #1
0
ファイル: tuningviews.py プロジェクト: SnowmanRM/Snowman
def tuningPage(request, pagenr):
	"""This method is loaded when the /tuning/tuningByRulePage/ is called. 
	It delivers the page specified page of tuning objects. """
	
	logger = logging.getLogger(__name__)
	
	context = {}
	
	# Get pagelength from the utility class.
	pagelength = UserSettings.getPageLength(request, pagetype=UserSettings.RULELIST)
	
	# We want pagenr with us in the template.
	context['pagenr'] = pagenr
	
	# We want pagelength with us in the template.
	context['pagelength'] = pagelength
	
	# The first page isnt hidden.
	if int(pagenr) == 1:
		context['ishidden'] = False
	else:
		context['ishidden'] = True
	
	# We multiply the paglength with the requested pagenr, this should give us the minimum range.
	minrange = (pagelength) * (int(pagenr)-1)
	
	# We add pagelength to the minumum range, this gives us the maximum range.
	maxrange = int(minrange) + (pagelength)
	
	try:
		# We get a total count of the number of objects.
		context['itemcount'] = EventFilter.objects.count()
		context['itemcount'] += DetectionFilter.objects.count()
		context['itemcount'] += Suppress.objects.count()
		# We get all the objects.
		eventFilterList = EventFilter.objects.all()
		detectionFilterList = DetectionFilter.objects.all()
		suppressList = Suppress.objects.all()
		# We combine all the objects into one big list.
		tuningList = list(chain(eventFilterList,detectionFilterList,suppressList))
	except:
		logger.warning("No sensors found.")
		raise Http404
	
	# We send a ranged set of the objects for processing.
	context['tuningList'] = tuningToTemplate(tuningList[minrange:maxrange])
	# Send to template.
	return render(request, 'tuning/tuningPage.tpl', context)
コード例 #2
0
ファイル: tuningviews.py プロジェクト: SnowmanRM/Snowman
def tuningSearch(request, pagenr):
	"""This method is loaded when the /tuning/tuningByRulePage/ is called. 
	It delivers the page specified page of tuning objects based on search parameters. """
	
	logger = logging.getLogger(__name__)
	
	context = {}
	
	# Get the two values from the HTTP POST request.
	searchstring = request.POST['searchs']
	searchfield = request.POST['searchf']
	
	
	# We set this value to true so that we can differentiate in the template.
	context['rulesearch'] = True
	
	# We want the searchstring with us in the template.
	context['searchstring'] = searchstring
	
	# Get pagelength from the utility class.
	pagelength = UserSettings.getPageLength(request, pagetype=UserSettings.RULELIST)
	
	# We want pagenr with us in the template.
	context['pagenr'] = "search"+pagenr
	
	# We want pagelength with us in the template.
	context['pagelength'] = pagelength
	
	# The first page isnt hidden.
	if int(pagenr) == 1:
		context['ishidden'] = False
	else:
		context['ishidden'] = True
	
	# We multiply the paglength with the requested pagenr, this should give us the minimum range.
	minrange = (pagelength) * (int(pagenr)-1)
	
	# We add pagelength to the minumum range, this gives us the maximum range.
	maxrange = int(minrange) + (pagelength)
	
	try:
		
		# We do different queries based on the searchfield string.
		if searchfield=='sid':
			# We get a total count of the number of objects.
			context['itemcount'] = EventFilter.objects.filter(rule__SID__istartswith=searchstring).count()
			context['itemcount'] += DetectionFilter.objects.filter(rule__SID__istartswith=searchstring).count()
			context['itemcount'] += Suppress.objects.filter(rule__SID__istartswith=searchstring).count()
			# We get all the objects.
			eventFilterList = EventFilter.objects.filter(rule__SID__istartswith=searchstring)
			detectionFilterList = DetectionFilter.objects.filter(rule__SID__istartswith=searchstring)
			suppressList = Suppress.objects.filter(rule__SID__istartswith=searchstring)
		elif searchfield=='name':
			# We get a total count of the number of objects.
			context['itemcount'] = EventFilter.objects.filter(rule__revisions__msg__icontains=searchstring).distinct().count()
			context['itemcount'] += DetectionFilter.objects.filter(rule__revisions__msg__icontains=searchstring).distinct().count()
			context['itemcount'] += Suppress.objects.filter(rule__revisions__msg__icontains=searchstring).distinct().count()
			# We get all the objects.
			eventFilterList = EventFilter.objects.filter(rule__revisions__msg__icontains=searchstring).distinct()
			detectionFilterList = DetectionFilter.objects.filter(rule__revisions__msg__icontains=searchstring).distinct()
			suppressList = Suppress.objects.filter(rule__revisions__msg__icontains=searchstring).distinct()
		elif searchfield=='sensor':
			# We get a total count of the number of objects.
			context['itemcount'] = EventFilter.objects.filter(sensor__name__icontains=searchstring).count()
			context['itemcount'] += DetectionFilter.objects.filter(sensor__name__icontains=searchstring).count()
			context['itemcount'] += Suppress.objects.filter(sensor__name__icontains=searchstring).count()
			# We get all the objects.
			eventFilterList = EventFilter.objects.filter(sensor__name__icontains=searchstring)
			detectionFilterList = DetectionFilter.objects.filter(sensor__name__icontains=searchstring)
			suppressList = Suppress.objects.filter(sensor__name__icontains=searchstring)
			
		# We combine all the objects into one big list.
		tuningList = list(chain(eventFilterList,detectionFilterList,suppressList))
	except:
		logger.warning("No sensors found.")
		raise Http404
	
	# We send a ranged set of the objects for processing.
	context['tuningList'] = tuningToTemplate(tuningList[minrange:maxrange])
	# Send to template.
	return render(request, 'tuning/tuningPage.tpl', context)