Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
scripts
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Benjamin Graillot
scripts
Commits
48919431
Commit
48919431
authored
Apr 16, 2017
by
Gabriel Detraz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Script de recherche dans les logs
parent
bea52125
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
192 additions
and
0 deletions
+192
-0
gestion/logsearch
gestion/logsearch
+192
-0
No files found.
gestion/logsearch
0 → 100755
View file @
48919431
#!/bin/bash
LOGFILE
=
""
DHCP
=
false
RADIUS
=
false
FILAIRE
=
false
WIFI
=
false
MAC
=()
IP
=()
LOGSOURCE
=
"file"
AUTH_FILES
=
"/var/log/filaire/global.log /var/log/wifi/global.log /var/log/cablage/global.log"
DEFAULT_LOGFILE
=
"/var/log/cablage/global.log"
FIL_NETS
=
"(138.231.1(3[6789]|4[0123]))"
WIFI_NETS
=
"(138.231.1(4[456789]|5[01]))"
SWITCHES_NETS
=
"(10.231.100)"
BORNES_NETS
=
"(10.231.148)"
FILTERS
=()
MAC_REGEX
=
"^(([a-fA-F0-9]{2}:){5}|([a-fA-F0-9]{2}-){5})[a-fA-F0-9]{2}$"
IPv4_REGEX
=
"^([0-9]{1,3}
\.
){3}[0-9]{1,3}$"
IPv6_REGEX
=
"^[0-9A-Fa-f]{0,4}:(([0-9A-Fa-f]{0,4}:){0,5}[0-9A-Fa-f]{0,4}|[0-9A-Fa-f]{0,4}(:[0-9A-Fa-f]{0,4}){0,5}):[0-9A-Fa-f]{0,4}$"
display_help
()
{
printf
"Usage: %s: [-d] [-r] [-f] [-w] [-m MACADDR] [-i IPADDR] [-s SOURCE] [-t TYPE] [-h]
\n
"
$1
printf
"
\n
"
printf
" Effectue une recherche dans les logs à des fins de diagnostic.
\n
"
printf
"
\n
"
printf
" -d : Rechercher les logs concernant les requêtes DHCP
\n
"
printf
" -r : Rechercher les logs concernant les requêtes RADIUS
\n
"
printf
" -f : Rechercher les logs concernant le filaire
\n
"
printf
" -w : Rechercher les logs concernant le wifi
\n
"
printf
" -m MACADDR : Rechercher les logs concernant MACADDR
\n
"
printf
" -i IPADDR : Rechercher les logs concernant IPADDR
\n
"
printf
" -s SOURCE : Fichier de log à examiner
\n
"
printf
" -t TYPE : Examiner les logs en temps réel ('live') ou ceux qui sont déjà consignés ('file')
\n
"
printf
" -h : Afficher ce message d'aide
\n
"
}
join
()
{
local
d
=
$1
shift
echo
-n
"
$1
"
shift
printf
"%s"
"
${
@/#/
$d
}
"
}
if
[
-z
"
$1
"
]
;
then
display_help
$0
exit
0
fi
while
getopts
"drfwhm:i:s:t:"
opt
;
do
case
$opt
in
d
)
DHCP
=
true
;;
r
)
RADIUS
=
true
;;
f
)
FILAIRE
=
true
;;
w
)
WIFI
=
true
;;
h
)
display_help
$0
exit
0
;;
m
)
if
[
-z
$OPTARG
]
;
then
echo
"Une adresse MAC doit être spécifiée avec l'option -m"
exit
1
elif
[[
"
$OPTARG
"
=
~
$MAC_REGEX
]]
;
then
TEMP_MAC
=
$(
echo
$OPTARG
|
tr
A-Z a-z |
sed
"s/
\(
[0-9a-f]
\{
2
\}\)
.*
\(
[0-9a-f]
\{
2
\}\)
.*
\(
[0-9a-f]
\{
2
\}\)
.*
\(
[0-9a-f]
\{
2
\}\)
.*
\(
[0-9a-f]
\{
2
\}\)
.*
\(
[0-9a-f]
\{
2
\}\)
/
\1
.
\2
.
\3
.
\4
.
\5
.
\6
/"
)
MAC+
=(
$TEMP_MAC
)
else
echo
"
$OPTARG
n'est pas une adresse MAC valide."
exit
1
fi
;;
i
)
if
[
-z
$OPTARG
]
;
then
echo
"Une adresse IPv(4|6) doit être spécifiée avec l'option -i"
exit
1
elif
[[
"
$OPTARG
"
=
~
$IPv4_REGEX
]]
;
then
SAVED_IFS
=
$IFS
IFS
=
'.'
TEMP_IP
=(
$OPTARG
)
IFS
=
$SAVED_IFS
if
[[
${
TEMP_IP
[0]
}
-le
255
&&
${
TEMP_IP
[1]
}
-le
255
&&
${
TEMP_IP
[2]
}
-le
255
&&
${
TEMP_IP
[3]
}
-le
255
]]
;
then
IP+
=(
"
$OPTARG
"
)
else
echo
"
$OPTARG
n'est pas une adresse IP valide"
exit
1
fi
elif
[[
"
$OPTARG
"
=
~
$IPv6_REGEX
]]
;
then
IP+
=(
"
$(
echo
$OPTARG
|
tr
A-Z a-z
)
"
)
else
echo
"
$OPTARG
n'est pas une adresse IP valide"
exit
1
fi
;;
t
)
if
[
-z
$OPTARG
]
;
then
echo
"Le mode de consultation des logs doit être spécifié avec l'option -t ('file' ou 'live')"
exit
1
fi
case
$OPTARG
in
live|file
)
LOGSOURCE
=
$OPTARG
;;
*
)
echo
"Le mode de consultation des logs doit être 'file' ou 'live'"
exit
1
;;
esac
;;
s
)
if
[
-z
$OPTARG
]
;
then
echo
"La source des logs doit être spécifiée si l'option -s est utilisée"
exit
1
fi
if
[
-f
$OPTARG
]
;
then
for
FILE
in
$AUTH_FILES
;
do
if
[
"
$(
realpath
-P
$OPTARG
)
"
=
$FILE
]
;
then
LOGFILE+
=(
$OPTARG
)
fi
done
else
echo
"Le fichier
$OPTARG
n'existe pas ou n'est pas un fichier valide."
exit
1
fi
;;
\?
)
echo
"Option invalide : -
$OPTARG
"
exit
1
;;
esac
done
if
[
"
$FILAIRE
"
=
"false"
]
&&
[
"
$WIFI
"
=
"false"
]
;
then
if
[
"
$DHCP
"
=
"true"
]
;
then
FILTERS+
=(
dhcpd
)
fi
if
[
"
$RADIUS
"
=
"true"
]
;
then
FILTERS+
=(
freeradius
)
fi
elif
[
"
$FILAIRE
"
=
"true"
]
;
then
if
[
"
$RADIUS
"
=
"true"
]
;
then
FILTERS+
=(
"(
\(
fil
\)
|NAS:.
$SWITCHES_NETS
)"
)
else
FILTERS+
=(
$FIL_NETS
)
fi
if
[
"
$DHCP
"
=
"true"
]
;
then
FILTERS+
=(
"dhcpd.*
$FIL_NETS
"
)
fi
elif
[
"
$WIFI
"
=
"true"
]
;
then
if
[
"
$RADIUS
"
=
"true"
]
;
then
FILTERS+
=(
"(
\(
wifi
\)
|NAS:.
$BORNES_NETS
)"
)
else
FILTERS+
=(
$WIFI_NETS
)
fi
if
[
"
$DHCP
"
=
"true"
]
;
then
FILTERS+
=(
"dhcpd.*
$WIFI_NETS
"
)
fi
fi
if
[
-n
${
MAC
[1]
}
]
;
then
FILTERS+
=(
${
MAC
[@]
}
)
fi
if
[
-n
${
IP
[1]
}
]
;
then
FILTERS+
=(
${
IP
[@]
}
)
fi
if
[
-z
"
${
LOGFILE
[1]
}
"
]
;
then
echo
"Aucun fichier de log spécifié :
$DEFAULT_LOGFILE
utilisé(s) par défaut"
LOGFILE+
=(
$DEFAULT_LOGFILE
)
fi
printf
"RegExp utilisée : %s
\n\n
"
"(
$(
join
'|'
${
FILTERS
[@]
}
)
)"
if
[
"
$LOGSOURCE
"
=
"live"
]
;
then
tail
-f
${
LOGFILE
[@]
}
|
grep
-i
-E
"(
$(
join
'|'
${
FILTERS
[@]
}
)
)"
--color
=
always
elif
[
"
$LOGSOURCE
"
=
"file"
]
;
then
grep
-i
-E
"(
$(
join
'|'
${
FILTERS
[@]
}
)
)"
--color
=
always
${
LOGFILE
[@]
}
fi
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment