filter3 näidis kasutades dialog programmi
This commit is contained in:
parent
4c1b365b06
commit
e5dddf33e3
@ -28,7 +28,9 @@ Bashis kirjutatud skript mis parsib standardsisendist ning kuvab tulemused stand
|
||||
|
||||
Käivitamiseks:
|
||||
|
||||
```bash
|
||||
(cat access.log; zcat access.log.1.gz) | top2
|
||||
```
|
||||
|
||||
# top4
|
||||
|
||||
@ -77,3 +79,20 @@ Pythoni variandi põhilised erisused:
|
||||
|
||||
* Jooksvalt pakib lahti .gz lõpulised failid
|
||||
* Jätab vahele failid mille sees otsitavat ajavahemikku kindlasti ei ole
|
||||
|
||||
# filter3
|
||||
|
||||
Küsib pseudograafilise kasutajaliidese abil kuupäeva ja minutite vahemikku ning paneb
|
||||
sama ```filter2``` programmi käima
|
||||
|
||||
Sõltuvuste paigaldamiseks
|
||||
|
||||
```bash
|
||||
apt install dialog
|
||||
```
|
||||
|
||||
Käivitamiseks:
|
||||
|
||||
```bash
|
||||
filter3 /var/log
|
||||
```
|
||||
|
@ -13,6 +13,10 @@ except IndexError:
|
||||
|
||||
try:
|
||||
scope_begin = datetime.strptime(sys.argv[2], "%Y-%m-%d %H:%M:%S")
|
||||
except ValueError:
|
||||
# Ei suutnud parsida kellaaega YYYY-mm-dd HH:MM:SS formaadis,
|
||||
# proovime test formaati veel
|
||||
scope_begin = datetime.strptime(sys.argv[2], "%d/%m/%Y %H:%M:%S")
|
||||
except IndexError:
|
||||
scope_begin = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
|
||||
|
||||
|
28
bin/filter3
Executable file
28
bin/filter3
Executable file
@ -0,0 +1,28 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Katkesta vea korral
|
||||
set -e
|
||||
|
||||
# Küsi kuupäeva ja kelaaega
|
||||
KPV=$(dialog --calendar 0 0 0 --stdout)
|
||||
KELLAAEG=$(dialog --timebox "Sisesta kellaaeg mida otsida" 0 0 --stdout)
|
||||
|
||||
# Loo ajutine fail menüüvalikute jaoks ning kustuta see igal juhul kui skript lõpetab
|
||||
VALIKUD_FAIL=$(mktemp)
|
||||
trap "rm -f $VALIKUD_FAIL" EXIT
|
||||
|
||||
# Ajavahemike valikud
|
||||
cat << EOF > $VALIKUD_FAIL
|
||||
1 "1 minut"
|
||||
2 "2 minutit"
|
||||
3 "3 minutit"
|
||||
5 "5 minutit"
|
||||
15 "veerand tundi"
|
||||
30 "pool tundi"
|
||||
EOF
|
||||
|
||||
AJAVAHEMIK=$(dialog --menu "Mis ajavahemikku otsida alates sisestatud kellaajast?" 0 0 0 --file $VALIKUD_FAIL --stdout)
|
||||
|
||||
clear
|
||||
set -x
|
||||
filter2 $1 "$KPV $KELLAAEG" $AJAVAHEMIK
|
34
raport.py
34
raport.py
@ -1,34 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
# encoding: utf-8
|
||||
|
||||
"""
|
||||
Parsi standardsisendist Apache logikirjed ja kuva edetabelid
|
||||
Käivitamiseks: (cat access.log; zcat access.log.1.gz) | python raport.py
|
||||
"""
|
||||
|
||||
import re
|
||||
import sys
|
||||
from collections import Counter
|
||||
from log_parsers import ApacheLogParser
|
||||
|
||||
hits = Counter() # IP-d kust tuldi
|
||||
urls = Counter() # URL-id mida külastati
|
||||
agents = Counter() # User agent mida kasutati külastamisel
|
||||
|
||||
for timestamp, log_entry, stack_trace in ApacheLogParser(sys.stdin):
|
||||
urls[log_entry.get("path")] += 1
|
||||
hits[log_entry.get("remote_addr")] += 1
|
||||
agents[log_entry.get("user_agent")] += 1
|
||||
|
||||
print "Top5 külastatud URL-id veebiserveris:"
|
||||
for path, count in urls.most_common(5):
|
||||
sys.stdout.write("% 9d %s\n" % (count, path))
|
||||
print
|
||||
print "Top5 külastusi teinud IP aadressid:"
|
||||
for remote_addr, count in hits.most_common(5):
|
||||
sys.stdout.write("% 9d %s\n" % (count, remote_addr))
|
||||
print
|
||||
print "Top5 kasutatud veebilehitsejad/OS-id:"
|
||||
for user_agent, count in agents.most_common(5):
|
||||
sys.stdout.write("% 9d %s\n" % (count, user_agent))
|
||||
|
Loading…
Reference in New Issue
Block a user