This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tg-indicateur
executable file
·231 lines (218 loc) · 9.02 KB
/
tg-indicateur
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/bin/bash
######## Declaration des variables ########
export RTUSER=xxxxxx
export RTPASSWD=xxxxxx
export RTSERVER=https://rt.giprecia.fr/rt/
OPTERR=0 #Permet d'eviter le message d'erreur de getopts
day=$(date "+%d/%m/%Y")
fday=$(date "+%d-%m-%Y-%H-%M")
sday=$(date "+%Y-%m-%d")
mday=$(date "+%B_%Y")
listStatus="new open stalled resolved"
fileStatus="new open stalled"
debug="false" #Permet d'activer le debug des requetes
expor="false"
#Coloration
VERT="\\033[1;32m"
NORMAL="\\033[0;39m"
ROUGE="\\033[1;31m"
ROSE="\\033[1;35m"
BLEU="\\033[1;34m"
BLANC="\\033[0;02m"
BLANCLAIR="\\033[1;08m"
JAUNE="\\033[1;33m"
CYAN="\\033[1;36m"
usage(){
echo "Usage: $0 [options]"
echo "--help ou -h : afficher l'aide"
echo "--version ou -v : afficher la version"
echo "--debug ou -d : permet d'afficher les requetes utilises"
echo "--export ou -e : export en csv les indicateurs avec le nom de fichier suivant [indicateurs_$fday.csv]"
}
# dump(){
# #Supprime la coloration pour sortie dans un fichier
# traitement | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g"
# }
export(){
tmpfile=$(mktemp)
destination="/home/ftp/share/Indicateur/$mday"
file="/tmp/indicateurs_$fday.csv"
#Supprime la coloration pour sortie dans un fichier
traitement | tee $tmpfile
echo
echo -e "Traitement des indicateurs \t ["$VERT"OK"$NORMAL"]"
cat $tmpfile | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" | sed -r "s/:/;/g" >> $file
echo -e "Creation du fichier $file \t ["$VERT"OK"$NORMAL"]"
rm -f $tmpfile
if [ ! -d "$destination" ]; then
mkdir -p $destination
echo -e "Creation du dossier $destination \t ["$VERT"OK"$NORMAL"]"
fi
if [ -d "$destination" ]; then
mv $file $destination
echo -e "Deplacement du fichier $file dans $destination \t ["$VERT"OK"$NORMAL"]"
fi
}
traitement(){
echo -e $ROSE"Indicateur du : "$day"$NORMAL";
nobody
file '01 - En attente de PEC'
file '02 - Incidents'
file '02.1 - Incidents ProActifs'
file '03 - SFR (Incidents)'
file '04 - Travaux Niveau I'
file '05 - Travaux Niveau II'
}
nobody(){
queryFile="( Queue = '01 - En attente de PEC' OR Queue = '02 - Incidents' OR Queue = '03 - SFR (Incidents)' OR Queue = '04 - Travaux Niveau I' OR Queue = '05 - Travaux Niveau II' OR Queue = '02.1 - Incidents ProActifs' )"
echo -e "$CYAN""Nobody :""$NORMAL";
request="Owner = 'nobody' AND (Status = 'new' OR Status = 'open' OR Status = 'stalled') AND $queryFile"
if [ "$debug" == "true" ]; then
query="$VERT : Requete => \"$request\""
else
query=""
fi
echo -e "$VERT""Total : "$ROUGE"$(rt ls -i "$request"| grep ticket -c)"$query"$NORMAL";
for i in $fileStatus
do
if [ $i == 'new' ]; then status="Nouveau : "; elif [ $i == 'open' ]; then status="Ouvert : "; elif [ $i == 'stalled' ]; then status="Stagnant : ";fi
request="Owner = 'nobody' AND Status = $i AND $queryFile"
if [ "$debug" == "true" ]; then
query="$VERT : Requete => \"$request\""
else
query=""
fi
echo -e "$VERT""$status"$ROUGE"$(rt ls -i "$request"| grep ticket -c)"$query"$NORMAL";
unset request
unset query
done
echo -e "$CYAN""Stagnant sans Motif Delai :""$NORMAL";
request="Owner = 'nobody' AND Status = 'stalled' AND $queryFile AND 'CF.{MotifDelai}' IS NULL"
if [ "$debug" == "true" ]; then
query="$VERT : Requete => \"$request\""
else
query=""
fi
echo -e "$VERT""Total : "$ROUGE"$(rt ls -i "$request"| grep ticket -c)"$query"$NORMAL";
echo -e "$CYAN""Stagnant avec Motif Delai :""$NORMAL";
request="Owner = 'nobody' AND Status = 'stalled' AND $queryFile AND 'CF.{MotifDelai}' IS NOT NULL"
if [ "$debug" == "true" ]; then
query="$VERT : Requete => \"$request\""
else
query=""
fi
echo -e "$VERT""Total : "$ROUGE"$(rt ls -i "$request"| grep ticket -c)"$query"$NORMAL";
declare -A listMD
listMD=(["A"]="Attente matériel" ["B"]="Attente Periode Creuse" ["C"]="Attente réponse établissement" ["D"]="Attente réponse RECIA" ["E"]="Attente retour niveau 2" ["F"]="Déplacement programmé" ["G"]="En cours de développement" ["H"]="Intervention programmée")
for elem in ${!listMD[*]}
do
text=$(echo ${listMD[${elem}]} | iconv -f utf8 -t ascii//TRANSLIT) #Soucis d'accent
request="Owner = 'nobody' AND Status = 'stalled' AND $queryFile AND 'CF.{MotifDelai}' = '${listMD[${elem}]}'"
if [ "$debug" == "true" ]; then
query="$VERT : Requete => \"$request\""
else
query=""
fi
echo -e "$VERT"$text" : "$ROUGE"$(rt ls -i "$request"| grep ticket -c)"$query"$NORMAL";
unset request
unset query
done
}
file(){
tg="( Owner = 'cblondeau' OR Owner = 'njoubert' OR Owner = 'ssanchez' OR Owner = 'dgelve' OR Owner = 'lleminoux' OR Owner = 'cfonck' OR Owner = 'stellier')"
recia="(Owner != 'cblondeau' AND Owner != 'njoubert' AND Owner != 'ssanchez' AND Owner != 'dgelve' AND Owner != 'lleminoux' AND Owner != 'cfonck' AND Owner != 'stellier' AND Owner !='nobody')"
queue=$1
echo -e "$CYAN""File - $queue :""$NORMAL";
request="Queue = '$queue' AND (Status = 'new' OR Status = 'open' OR Status = 'stalled')"
if [ "$debug" == "true" ]; then
query="$VERT : Requete => \"$request\""
else
query=""
fi
echo -e "$VERT""Total : "$ROUGE"$(rt ls -i "$request" | grep ticket -c)"$query"$NORMAL";
for i in $listStatus
do
resolv=''
if [ $i == 'new' ]; then status="Nouveau : "; elif [ $i == 'open' ]; then status="Ouvert : "; elif [ $i == 'stalled' ]; then status="Stagnant : "; elif [ $i == 'resolved' ]; then status="Resolu : "; resolv="AND Resolved = '$sday'"; fi
request="Queue = '$queue' AND Status = '$i' $resolv"
if [ "$debug" == "true" ]; then
query="$VERT : Requete => \"$request\""
else
query=""
fi
echo -e "$VERT""$status"$ROUGE"$(rt ls -i "$request"| grep ticket -c)"$query"$NORMAL";
unset request
unset query
done
for i in $listStatus
do
resolv=''
if [ $i == 'new' ]; then status="Nobody - Nouveau : "; elif [ $i == 'open' ]; then status="Nobody - Ouvert : "; elif [ $i == 'stalled' ]; then status="Nobody - Stagnant : "; elif [ $i == 'resolved' ]; then status="Nobody - Resolu : "; resolv=" AND Resolved = '$sday'";fi
request="Owner = 'nobody' AND Queue = '$queue' AND Status = '$i' $resolv"
if [ "$debug" == "true" ]; then
query="$VERT : Requete => \"$request\""
else
query=""
fi
echo -e "$BLEU""$status"$ROUGE"$(rt ls -i "$request"| grep ticket -c)"$query"$NORMAL";
unset request
unset query
done
for i in $listStatus
do
resolv=''
if [ $i == 'new' ]; then status="TG - Nouveau : "; elif [ $i == 'open' ]; then status="TG - Ouvert : "; elif [ $i == 'stalled' ]; then status="TG - Stagnant : "; elif [ $i == 'resolved' ]; then status="TG - Resolu : "; resolv=" AND Resolved = '$sday'";fi
request="$tg AND Queue = '$queue' AND Status = '$i' $resolv"
if [ "$debug" == "true" ]; then
query="$VERT : Requete => \"$request\""
else
query=""
fi
echo -e "$ROSE""$status"$ROUGE"$(rt ls -i "$request"| grep ticket -c)"$query"$NORMAL";
unset request
unset query
done
for i in $listStatus
do
resolv=''
if [ $i == 'new' ]; then status="Recia - Nouveau : "; elif [ $i == 'open' ]; then status="Recia - Ouvert : "; elif [ $i == 'stalled' ]; then status="Recia - Stagnant : "; elif [ $i == 'resolved' ]; then status="Recia - Resolu : "; resolv=" AND Resolved = '$sday'";fi
request="$recia AND Queue = '$queue' AND Status = '$i' $resolv "
if [ "$debug" == "true" ]; then
query="$VERT : Requete => \"$request\""
else
query=""
fi
echo -e "$JAUNE""$status"$ROUGE"$(rt ls -i "$request"| grep ticket -c)"$query"$NORMAL";
unset request
unset query
done
}
# on verifie les options
while getopts "edvh-:" opt ; do
if [ $opt = "-" ] ; then
case $OPTARG in
help ) opt="h" ;;
version ) opt="v" ;;
debug ) opt="d" ;;
export ) opt="e" ;;
* )
echo "Option longue inconnue..."
break ;;
esac
fi
case $opt in
h ) usage ;;
v ) echo "Version 2.0" ;;
d ) debug="true" ;;
e ) export && expor="true" ;;
? ) echo "Option inconnue" ;;
esac
done
# Pas de parametre on lance le script en affichage directement
if [ $# -lt 1 ]; then
traitement
else
if [ "$debug" == "true" ] && [ "$expor" == "false" ];then
traitement
fi
fi