forked from shinken-solutions/shinken
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·2051 lines (1873 loc) · 65.8 KB
/
install
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
#set -x
#Copyright (C) 2009-2012 :
# Gabes Jean, [email protected]
# Gerhard Lausser, [email protected]
# David GUENAULT, [email protected]
#
#This file is part of Shinken.
#
#Shinken is free software: you can redistribute it and/or modify
#it under the terms of the GNU Affero General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#Shinken is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU Affero General Public License for more details.
#
#You should have received a copy of the GNU Affero General Public License
#along with Shinken. If not, see <http://www.gnu.org/licenses/>.
#####################
### ENVIRONNEMENT ###
#####################
export myscripts=$(readlink -f $(dirname $0))
src=$myscripts
. $myscripts/install.d/shinken.conf
if [ -f $TMP/shinken.install.log ]
then
rm -f $TMP/shinken.install.log
fi
function remove(){
cadre "Removing shinken" green
skill
if [ -d "$TARGET" ]
then
cecho " > Removing $TARGET" green
rm -Rf $TARGET
fi
if [ -h "/etc/default/shinken" ]
then
cecho " > Removing defaults" green
rm -Rf /etc/default/shinken
fi
if [ -f "/etc/init.d/shinken" ]
then
cecho " > Removing startup scripts" green
case $CODE in
REDHAT)
chkconfig shinken off
chkconfig --del shinken
;;
DEBIAN)
update-rc.d -f shinken remove >> $TMP/shinken.install.log 2>&1
;;
esac
fi
rm -f /etc/init.d/shinken*
if [ -d "$PNPPREFIX" ]
then
doremove="n"
cread " > found a pnp4nagios installation : do you want to remove it ? (y|N) => " yellow "n" "y n"
if [ "$readvalue" == "y" ]
then
cecho " > Removing pnp4nagios" green
rm -Rf $PNPPREFIX
case $CODE in
REDHAT)
/etc/init.d/npcd stop >> $TMP/shinken.install.log 2>&1
chkconfig npcd off >> $TMP/shinken.install.log 2>&1
chkconfig --del npcd >> $TMP/shinken.install.log 2>&1
rm -f /etc/init.d/npcd >> $TMP/shinken.install.log 2>&1
rm -f /etc/httpd/conf.d/pnp4nagios.conf >> $TMP/shinken.install.log 2>&1
/etc/init.d/httpd restart >> $TMP/shinken.install.log 2>&1
;;
DEBIAN)
/etc/init.d/npcd stop >> $TMP/shinken.install.log 2>&1
update-rc.d -f npcd remove >> $TMP/shinken.install.log 2>&1
rm -f /etc/init.d/npcd >> $TMP/shinken.install.log 2>&1
rm -f /etc/apache2/conf.d/pnp4nagios.conf >> $TMP/shinken.install.log 2>&1
/etc/init.d/apache2 restart >> $TMP/shinken.install.log 2>&1
;;
esac
else
cecho " > Aborting uninstallation of pnp4nagios" yellow
fi
fi
if [ -d "$MKPREFIX" ]
then
doremove="n"
cread " > found a check_mk multisite installation : do you want to remove it ? (y|N) => " yellow "n" "y n"
if [ "$readvalue" == "y" ]
then
cecho " > Removing check_mk multisite" green
rm -Rf $MKPREFIX
if [ -d $PNPPREFIX.MK ]
then
rm -Rf $PNPPREFIX.MK
fi
cecho " > Remove sudoers configuration" green
sed -i "/^# Needed for WATO/,+2d" /etc/sudoers
cecho " > Remove apache configuration" green
case $CODE in
REDHAT)
rm -f /etc/httpd/conf.d/zzz_check_mk.conf >> $TMP/shinken.install.log 2>&1
/etc/init.d/httpd restart >> $TMP/shinken.install.log 2>&1
;;
DEBIAN)
rm -f /etc/apache2/conf.d/zzz_check_mk.conf >> $TMP/shinken.install.log 2>&1
/etc/init.d/apache2 restart >> $TMP/shinken.install.log 2>&1
;;
esac
else
cecho " > Aborting uninstallation of check_mk multisite" yellow
fi
fi
if [ -d "$NAGVISPREFIX" ]
then
doremove="n"
cread " > found a nagvis installation : do you want to remove it ? (y|N) => " yellow "n" "y n"
if [ "$readvalue" == "y" ]
then
cecho " > Removing nagvis" green
rm -Rf $NAGVISPREFIX
case $CODE in
REDHAT)
rm -f /etc/httpd/conf.d/nagvis.conf >> $TMP/shinken.install.log 2>&1
/etc/init.d/httpd restart >> $TMP/shinken.install.log 2>&1
;;
DEBIAN)
rm -f /etc/apache2/conf.d/nagvis.conf >> $TMP/shinken.install.log 2>&1
/etc/init.d/apache2 restart >> $TMP/shinken.install.log 2>&1
;;
esac
else
cecho " > Aborting uninstallation of nagvis" yellow
fi
fi
return 0
}
function purgeSQLITE(){
cadre "Purge livestatus db logs" green
if [ ! -f $TARGET/var/livestatus.db ]
then
cecho " > Livestatus db not found " yellow
exit 1
fi
skill >> $TMP/shinken.install.log 2>&1
cecho " > We keep $KEEPDAYSLOG days of logs" green
sqlite3 $TARGET/var/livestatus.db "delete from logs where time < strftime('%s', 'now') - 3600*24*$KEEPDAYSLOG"
cecho " > Vaccum the sqlite DB" green
sqlite3 $TARGET/var/livestatus.db VACUUM
}
function skill(){
/etc/init.d/shinken stop >> $TMP/shinken.install.log 2>&1
pc=$(ps -aef | grep "$TARGET" | grep -v "grep" | wc -l )
if [ $pc -ne 0 ]
then
OLDIFS=$IFS
IFS=$'\n'
for p in $(ps -aef | grep "$TARGET" | grep -v "grep" | awk '{print $2}')
do
cecho " > Killing $p " green
kill -9 $p
done
IFS=$OLDIFS
fi
rm -Rf $TMP/bad_start*
rm -Rf $TARGET/var/*.pid
}
function setdirectives(){
directives=$1
fic=$2
mpath=$3
cecho " > Going to $mpath" green
cd $mpath
for pair in $directives
do
directive=$(echo $pair | awk -F= '{print $1}')
value=$(echo $pair | awk -F= '{print $2}')
cecho " > Setting $directive to $value in $fic" green
sed -i 's#^\# \?'$directive'=\(.*\)$#'$directive'='$value'#g' $mpath/etc/$(basename $fic)
done
}
##############################
### INSTALLATION FUNCTIONS ###
##############################
function create_user(){
cadre "Creating user" green
if [ ! -z "$(cat /etc/passwd | grep $SKUSER)" ]
then
cecho " > User $SKUSER already exists" yellow
else
useradd -s /bin/bash $SKUSER -m -d /home/$SKUSER
fi
usermod -G $SKGROUP $SKUSER
}
function check_exist(){
cadre "Checking for existing installation" green
if [ -d "$TARGET" ]
then
cecho " > Target folder already exists" red
exit 2
fi
if [ -e "/etc/init.d/shinken" ]
then
cecho " > Init scripts already exists" red
exit 2
fi
if [ -L "/etc/default/shinken" ]
then
cecho " > Shinken default already exists" red
exit 2
fi
}
function shinken_exist(){
if [ -d $TARGET ]
then
echo 1
return 1
else
echo 0
return 0
fi
}
function installpkg(){
type=$1
package=$2
if [ "$type" == "python" ]
then
easy_install $package >> $TMP/shinken.install.log 2>&1
return $?
fi
case $CODE in
REDHAT)
yum install -yq $package >> $TMP/shinken.install.log 2>&1
if [ $? -ne 0 ]
then
return 2
fi
;;
DEBIAN)
apt-get install -y $package >> $TMP/shinken.install.log 2>&1
if [ $? -ne 0 ]
then
return 2
fi
;;
esac
return 0
}
function debinstalled(){
package=$1
if [ -z "$(dpkg -l $package | grep "^ii")" ]
then
return 1
else
return 0
fi
}
function prerequisites(){
cadre "Checking prerequisites" green
# common prereq
bins="wget sed awk grep python bash"
for b in $bins
do
rb=$(which $b >> $TMP/shinken.install.log 2>&1)
if [ $? -eq 0 ]
then
cecho " > Checking for $b : OK" green
else
cecho " > Checking for $b : NOT FOUND" red
exit 2
fi
done
# distro prereq
case $CODE in
REDHAT)
case $VERS in
[5-6])
PACKAGES=$YUMPKGS
QUERY="rpm -q "
cd $TMP
$QUERY $EPELNAME >> $TMP/shinken.install.log 2>&1
if [ $? -ne 0 ]
then
if [ $SKIPPREREQUISITES -eq 1 ]
then
cecho " SKIPPREREQUISITES enabled : won't install $EPEL" red
else
cecho " > Installing $EPELPKG" yellow
wget $WGETPROXY $EPEL >> $TMP/shinken.install.log 2>&1
if [ $? -ne 0 ]
then
cecho " > Error while trying to download EPEL repositories" red
exit 2
fi
rpm -Uvh ./$EPELPKG >> $TMP/shinken.install.log 2>&1
fi
else
cecho " > $EPELPKG already installed" green
fi
;;
# 6)
# PACKAGES=$YUMPKGS
# QUERY="rpm -q "
# ;;
*)
cecho " > Unsupported RedHat/CentOs version" red
exit 2
;;
esac
;;
DEBIAN)
PACKAGES=$APTPKGS
apt-get update >> $TMP/shinken.install.log 2>&1
QUERY="debinstalled "
;;
esac
for p in $PACKAGES
do
$QUERY $p >> $TMP/shinken.install.log 2>&1
if [ $? -ne 0 ]
then
if [ $SKIPPREREQUISITES -eq 1 ]
then
cecho " > SKIPPREQUISITES enabled : won't install $p" red
else
cecho " > Installing $p " yellow
installpkg pkg $p
if [ $? -ne 0 ]
then
cecho " > Error while trying to install $p" red
exit 2
fi
fi
else
cecho " > Package $p already installed " green
fi
done
# python prereq
if [ "$CODE" = "REDHAT" ]
then
case $VERS in
5)
if [ $SKIPPREREQUISITES -eq 1 ]
then
cecho " > SKIPPREQUISITES enabled : won't install $RHELSETUPTOOLS " red
else
# install setup tools for python 26
export PY="python26"
export PYEI="easy_install-2.6"
if [ ! -d "setuptools-$SETUPTOOLSVERS" ]
then
cecho " > Downloading setuptools for python 2.6" green
wget $WGETPROXY $RHELSETUPTOOLS >> $TMP/shinken.install.log 2>&1
tar zxvf setuptools-$SETUPTOOLSVERS.tar.gz >> $TMP/shinken.install.log 2>&1
fi
cecho " > Installing setuptools for python 2.6" green
cd setuptools-$SETUPTOOLSVERS >> $TMP/shinken.install.log 2>&1
python26 setup.py install >> $TMP/shinken.install.log 2>&1
fi
PYLIBS=$PYLIBSRHEL
;;
6)
export PY="python"
export PYEI="easy_install"
PYLIBS=$PYLIBSRHEL6
;;
esac
for p in $PYLIBS
do
module=$(echo $p | awk -F: '{print $1'})
import=$(echo $p | awk -F: '{print $2'})
$PY $myscripts/install.d/tools/checkmodule.py -m $import >> $TMP/shinken.install.log 2>&1
if [ $? -eq 2 ]
then
if [ $SKIPPREREQUISITES -eq 1 ]
then
cecho " > SKIPPREQUISITES enabled : won't install $p " red
else
cecho " > Module $module ($import) not found. Installing..." yellow
$PYEI $module >> $TMP/shinken.install.log 2>&1
fi
else
cecho " > Module $module found." green
fi
done
elif [ "$CODE" == "DEBIAN" ]
then
export PY="python"
export PYEI="easy_install"
PYLIBS=$PYLIBSDEB
for p in $PYLIBS
do
module=$(echo $p | awk -F: '{print $1'})
import=$(echo $p | awk -F: '{print $2'})
$PY $myscripts/install.d/tools/checkmodule.py -m $import >> $TMP/shinken.install.log 2>&1
if [ $? -eq 2 ]
then
if [ $SKIPPREREQUISITES -eq 1 ]
then
cecho " > SKIPPREQUISITES enabled : won't install $p " red
else
cecho " > Module $module ($import) not found. Installing..." yellow
$PYEI $module >> $TMP/shinken.install.log 2>&1
fi
else
cecho " > Module $module found." green
fi
done
fi
}
function check_distro(){
cadre "Verifying compatible distros" green
if [ ! -e /usr/bin/lsb_release ]
then
cecho " > No compatible distribution found" red
cecho " > maybe the lsb_release utility is not found" red
cecho " > on redhat like distro you should try yum install redhat-lsb"
exit 2
fi
if [ -z "$CODE" ]
then
cecho " > $DIST is not supported" red
exit 2
fi
versionok=0
distrook=0
for d in $DISTROS
do
distro=$(echo $d | awk -F: '{print $1}')
version=$(echo $d | awk -F: '{print $2}')
if [ "$CODE" = "$distro" ]
then
if [ "$version" = "" ]
then
cecho " > Found $CODE ($DIST $VERS $ARCH)" green
cecho " > Version checking for $DIST is not needed" green
versionok=1
return
else
if [ "$VERS" = "$version" ]
then
cecho " > Found $CODE ($DIST $VERS $ARCH)" green
versionok=1
return
fi
fi
fi
done
if [ $versionok -ne 1 ]
then
cecho " > $DIST $VERS is not supported" red
exit 2
fi
}
function get_from_git(){
cadre "Getting shinken" green
cd $TMP
if [ -e "shinken" ]
then
rm -Rf shinken
fi
env GIT_SSL_NO_VERIFY=true git clone $GIT >> $TMP/shinken.install.log 2>&1
cd shinken
cecho " > Switching to version $VERSION" green
git checkout $VERSION >> $TMP/shinken.install.log 2>&1
export src=$TMP/shinken
# clean up .git folder
rm -Rf .git
}
function relocate(){
cadre "Relocate source tree to $TARGET" green
# relocate source tree
cd $TARGET
# relocate macros
for f in $(find $TARGET/install.d/tools/macros | grep "\.macro$")
do
cecho " > relocating macro $f" green
sed -i "s#__PREFIX__#$TARGET#g" $f
done
# relocate nagios plugin path
sed -i "s#/usr/lib/nagios/plugins#$TARGET/libexec#g" ./etc/resource.cfg
sed -i "s#/usr/local/shinken/libexec#$TARGET/libexec#g" ./etc/resource.cfg
# relocate default /usr/local/shinken path
for fic in $(find . | grep -v "shinken-install" | grep -v "\.pyc$" | xargs grep -snH "/usr/local/shinken" --color | cut -f1 -d' ' | awk -F : '{print $1}' | sort | uniq)
do
cecho " > Processing $fic" green
cp "$fic" "$fic.orig"
#sed -i 's#/opt/shinken#'$TARGET'#g' $fic
sed -i 's#/usr/local/shinken#'$TARGET'#g' "$fic"
done
# when read hat 5 try to use python26
if [ "$CODE" = "REDHAT" ]
then
if [ "$VERS" = "5" ]
then
cecho " > Translating python version to python26" green
for fic in $(find $TARGET | grep "\.py$")
do
sed -i "s#/usr/bin/env python#/usr/bin/python26#g" $fic
done
# also try to translate python script without py extension
for fic in $(find $TARGET/bin)
do
if [ ! -z "$(file $fic | grep "python")" ]
then
sed -i "s#/usr/bin/env python#/usr/bin/python26#g" $fic
fi
done
fi
fi
# set some directives
cadre "Set some configuration directives" green
directives="workdir=$TARGET/var user=$SKUSER group=$SKGROUP"
for fic in $(ls -1 etc/*.ini)
do
cecho " > Processing $fic" green;
setdirectives "$directives" $fic $TARGET
#cp -f $fic $TARGET/etc/;
done
# relocate default file
cd $TARGET/bin/default
cat $TARGET/bin/default/shinken.in | sed -e 's#LOG\=\(.*\)$#LOG='$TARGET'/var#g' -e 's#RUN\=\(.*\)$#RUN='$TARGET'/var#g' -e 's#ETC\=\(.*\)$#ETC='$TARGET'/etc#g' -e 's#VAR\=\(.*\)$#VAR='$TARGET'/var#g' -e 's#BIN\=\(.*\)$#BIN='$TARGET'/bin#g' > $TARGET/bin/default/shinken
# relocate init file
cd $TARGET/bin/init.d
mv shinken shinken.in
cat shinken.in | sed -e "s#\#export PYTHONPATH=.*#export PYTHONPATH="$TARGET"#g" > $TARGET/bin/init.d/shinken
}
function fix(){
cadre "Applying various fixes" green
chmod +x /etc/init.d/shinken
chmod +x /etc/default/shinken
chmod +x $TARGET/bin/init.d/shinken
chown -R $SKUSER:$SKGROUP $TARGET
chmod -R g+w $TARGET
# remove tests directory
rm -Rf $TARGET/test
}
function enable(){
cadre "Enabling startup scripts" green
cp $TARGET/bin/init.d/shinken* /etc/init.d/
case $DISTRO in
REDHAT)
cecho " > Enabling $DIST startup script" green
chkconfig --add shinken
chkconfig shinken on
;;
DEBIAN)
cecho " > Enabling $DIST startup script" green
update-rc.d shinken defaults >> $TMP/shinken.install.log 2>&1
;;
esac
}
function sinstall(){
#cecho "Installing shinken" green
check_distro
check_exist
prerequisites
create_user
cp -Rf $src $TARGET
relocate
ln -s $TARGET/bin/default/shinken /etc/default/shinken
cp $TARGET/bin/init.d/shinken* /etc/init.d/
mkdir -p $TARGET/var/archives
enableretention
if [ "$LOGSTORE" == "mongo" ]
then
enablemongologs
fi
fix
cecho " > Starting shinken" green
/etc/init.d/shinken start
cecho "+------------------------------------------------------------------------------" green
cecho "| Shinken is now installed on your server " green
cecho "| You can start it with /etc/init.d/shinken start " green
cecho "| The Web Interface is available at : http://localhost:7767" green
cecho "+------------------------------------------------------------------------------" green
}
########################
### BACKUP FUNCTIONS ###
########################
function backup(){
cadre "Backup shinken configuration, plugins and data" green
skill
if [ ! -e $BACKUPDIR ]
then
mkdir $BACKUPDIR
fi
mkdir -p $BACKUPDIR/bck-shinken.$DATE
# Sugg :
# Add : cp -Rfp $TARGET/bin $BACKUPDIR/bck-shinken.$DATE/ line to backup bin
cp -Rfp $TARGET/etc $BACKUPDIR/bck-shinken.$DATE/
cp -Rfp $TARGET/libexec $BACKUPDIR/bck-shinken.$DATE/
cp -Rfp $TARGET/var $BACKUPDIR/bck-shinken.$DATE/
cecho " > Backup done. Id is $DATE"
}
function backuplist(){
cadre "List of available backups in $BACKUPDIR" green
for d in $(ls -1 $BACKUPDIR | grep "bck-shinken" | awk -F. '{print $2}')
do
cecho " > $d" green
done
}
function restore(){
cadre "Restore shinken configuration, plugins and data" green
skill
if [ ! -e $BACKUPDIR ]
then
cecho " > Backup folder not found" red
exit 2
fi
if [ -z $1 ]
then
cecho " > No backup timestamp specified" red
backuplist
exit 2
fi
if [ ! -e $BACKUPDIR/bck-shinken.$1 ]
then
cecho " > Backup not found : $BACKUPDIR/bck-shinken.$1 " red
backuplist
exit 2
fi
rm -Rf $TARGET/etc
rm -Rf $TARGET/libexec
rm -Rf $TARGET/var
cp -Rfp $BACKUPDIR/bck-shinken.$1/* $TARGET/
cecho " > Restoration done" green
}
########################
### UPDATE FUNCTIONS ###
########################
function supdate(){
curpath=$(pwd)
if [ "$src" == "$TARGET" ]
then
cecho "You should use the source tree to update and not use the target folder !!!!!" red
exit 2
fi
cadre "Updating shinken" green
skill
backup
remove
get_from_git
cp -Rf $src $TARGET
relocate
ln -sf $TARGET/bin/default/shinken /etc/default/shinken
cp $TARGET/bin/init.d/shinken* /etc/init.d/
mkdir -p $TARGET/var/archives
fix
restore $DATE
}
##############################
### EXPLOITATION FUNCTIONS ###
##############################
function compresslogs(){
cadre "Compress rotated logs" green
if [ ! -d $TARGET/var/archives ]
then
cecho " > Archives directory not found" yellow
exit 0
fi
cd $TARGET/var/archives
if [ ! -z "$(ls)" ]
then
for l in $(ls ./*.log)
do
file=$(basename $l)
if [ -e $file ]
then
cecho " > Processing $file" green
tar czf $file.tar.gz $file
rm -f $file
fi
done
fi
}
function shelp(){
cat $myscripts/install.d/README
}
########################
### CONFIG FUNCTIONS ###
########################
function cleanconf(){
if [ -z "$myscripts" ]
then
cecho " > Files/Folders list not found" yellow
exit 2
else
for f in $(cat $myscripts/install.d/config.files)
do
cecho " > Removing $TARGET/etc/$f" green
rm -Rf $TARGET/etc/$f
done
fi
}
function fixsudoers(){
cecho " > Fix /etc/sudoers file for shinken integration" green
cp /etc/sudoers /etc/sudoers.$(date +%Y%m%d%H%M%S)
cat $myscripts/install.d/sudoers.centreon | sed -e 's#TARGET#'$TARGET'#g' >> /etc/sudoers
}
function fixcentreondb(){
cecho " > Fix centreon database path for shinken integration" green
# get existing db access
host=$(cat /etc/centreon/conf.pm | grep "mysql_host" | awk '{print $3}' | sed -e "s/\"//g" -e "s/;//g")
user=$(cat /etc/centreon/conf.pm | grep "mysql_user" | awk '{print $3}' | sed -e "s/\"//g" -e "s/;//g")
pass=$(cat /etc/centreon/conf.pm | grep "mysql_passwd" | awk '{print $3}' | sed -e "s/\"//g" -e "s/;//g")
db=$(cat /etc/centreon/conf.pm | grep "mysql_database_oreon" | awk '{print $3}' | sed -e "s/\"//g" -e "s/;//g")
cp $myscripts/install.d/centreon.sql $TMP/centreon.sql
sed -i 's#TARGET#'$TARGET'#g' $TMP/centreon.sql
sed -i 's#CENTREON#'$db'#g' $TMP/centreon.sql
if [ -z "$pass" ]
then
mysql -h $host -u $user $db < $TMP/centreon.sql
else
mysql -h $host -u $user -p$pass $db < $TMP/centreon.sql
fi
}
function fixforfan(){
if [ ! -z "cat /etc/issue | grep FAN" ]
then
chown -R apache:nagios $TARGET/etc
chmod -R g+rw $TARGET/etc/*
fi
}
# ENABLE MONGO STORAGE FOR LOGS
function enablemongologs(){
cecho " > Enable mongodb log storage" green
export PYTHONPATH=$TARGET
export PY="$(pythonver)"
result=$($PY $TARGET/install.d/tools/skonf.py -a macros -f $TARGET/install.d/tools/macros/enable_log_mongo.macro -d $MONGOSERVER)
if [ $? -ne 0 ]
then
cecho " > There was an error while trying to enable mongo log storage ($result)" red
exit 2
fi
}
function enablendodb(){
cecho " > FIX shinken ndo configuration" green
# get existing db access
host=$(cat /etc/centreon/conf.pm | grep "mysql_host" | awk '{print $3}' | sed -e "s/\"//g" -e "s/;//g")
user=$(cat /etc/centreon/conf.pm | grep "mysql_user" | awk '{print $3}' | sed -e "s/\"//g" -e "s/;//g")
pass=$(cat /etc/centreon/conf.pm | grep "mysql_passwd" | awk '{print $3}' | sed -e "s/\"//g" -e "s/;//g")
db="centreon_status"
# add ndo module to broker
# first get existing broker modules
export PYTHONPATH=$TARGET
export PY="$(pythonver)"
result=$($PY $TARGET/install.d/tools/skonf.py -a macros -f $TARGET/install.d/tools/macros/ces_enable_ndo.macro -d $host,$db,$user,$pass)
if [ $? -ne 0 ]
then
cecho $result red
exit 2
fi
}
function enableretention(){
cecho " > Enable retention for broker scheduler and arbiter" green
if [ "$RETENTIONMODULE" == "mongo" ]
then
export PYTHONPATH=$TARGET
export PY="$(pythonver)"
result=$($PY $TARGET/install.d/tools/skonf.py -a macros -f $TARGET/install.d/tools/macros/enable_retention_mongo.macro)
if [ $? -ne 0 ]
then
cecho $result red
exit 2
fi
else
export PYTHONPATH=$TARGET
export PY="$(pythonver)"
result=$($PY $TARGET/install.d/tools/skonf.py -a macros -f $TARGET/install.d/tools/macros/enable_retention.macro)
if [ $? -ne 0 ]
then
cecho $result red
exit 2
fi
fi
}
function enableperfdata(){
cecho " > Enable perfdata " green
export PYTHONPATH=$TARGET
export PY="$(pythonver)"
cecho " > Getting existing broker modules list" green
modules=$($PY $TARGET/install.d/tools/skonf.py -a getdirective -f $TARGET/etc/shinken-specific.cfg -o broker -d modules)
if [ -z "$modules" ]
then
modules="Service-Perfdata, Host-Perfdata"
else
modules=$modules", Service-Perfdata, Host-Perfdata"
fi
result=$($PY $TARGET/install.d/tools/skonf.py -q -a setparam -f $TARGET/etc/shinken-specific.cfg -o broker -d modules -v "$modules")
cecho " > $result" green
}
function setdaemonsaddresses(){
export PYTHONPATH=$TARGET
export PY="$(pythonver)"
localip=$(ifconfig $IF | grep "^ *inet adr:" | awk -F : '{print $2}' | awk '{print $1}')
result=$($PY $TARGET/install.d/tools/skonf.py -q -a setparam -f $TARGET/etc/shinken-specific.cfg -o arbiter -d address -v "$localip")
cecho " > $result" green
result=$($PY $TARGET/install.d/tools/skonf.py -q -a setparam -f $TARGET/etc/shinken-specific.cfg -o scheduler -d address -v "$localip")
cecho " > $result" green
result=$($PY $TARGET/install.d/tools/skonf.py -q -a setparam -f $TARGET/etc/shinken-specific.cfg -o reactionner -d address -v "$localip")
cecho " > $result" green
result=$($PY $TARGET/install.d/tools/skonf.py -q -a setparam -f $TARGET/etc/shinken-specific.cfg -o receiver -d address -v "$localip")
cecho " > $result" green
result=$($PY $TARGET/install.d/tools/skonf.py -q -a setparam -f $TARGET/etc/shinken-specific.cfg -o poller -d address -v "$localip" -r "poller_name=poller-1")
cecho " > $result" green
}
function enableCESCentralDaemons(){
setdaemons "arbiter reactionner receiver scheduler broker poller"
}
function enableCESPollerDaemons(){
setdaemons "poller"
}
function disablenagios(){
chkconfig nagios off
chkconfig ndo2db off
/etc/init.d/nagios stop >> $TMP/shinken.install.log 2>&1
/etc/init.d/ndo2db stop >> $TMP/shinken.install.log 2>&1
}
function setdaemons(){
daemons="$(echo $1)"
avail="AVAIL_MODULES=\"$daemons\""
cecho " > Enabling the followings daemons : $daemons" green
sed -i "s/^AVAIL_MODULES=.*$/$avail/g" /etc/init.d/shinken
}
function fixHtpasswdPath(){
export PYTHONPATH=$TARGET
export PY="$(pythonver)"
# fix the htpasswd.users file path for WEBUI authentication
result=$($PY $TARGET/install.d/tools/skonf.py -f $TARGET/etc/shinken-specific.cfg -a setparam -o module -r "module_name=Apache_passwd" -d "passwd" -v "$TARGET/etc/htpasswd.users")
cecho " > $result" green
}
# addons installation
# mongodb
function install_mongodb(){
cadre "Install mongodb server" green
case $CODE in
REDHAT)
if [ ! -f "/etc/yum.repos.d/10gen.repo" ]
then
cp install.d/10gen.repo.in /etc/yum.repos.d/10gen.repo
case $ARCH in
i386)
MARCH=i686
;;
*)
MARCH=$ARCH
;;
esac
sed -i "s/__ARCH__/"$MARCH"/g" /etc/yum.repos.d/10gen.repo
yum clean all >> $TMP/shinken.install.log 2>&1
yum -y install mongo-10gen mongo-10gen-server >> $TMP/shinken.install.log 2>&1
chkconfig --add mongod >> $TMP/shinken.install.log 2>&1
chkconfig mongod on >> $TMP/shinken.install.log 2>&1
cecho " > Start mongodb server" green
/etc/init.d/mongod start >> $TMP/shinken.install.log 2>&1
else
cecho "Allready installed" red
exit 2
fi
;;
DEBIAN)
apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10 >> $TMP/shinken.install.log 2>&1
echo "deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen" > /etc/apt/sources.list.d/10gen.list
apt-get update >> $TMP/shinken.install.log 2>&1
apt-get install -y mongodb-10gen >> $TMP/shinken.install.log 2>&1
;;
*)
cecho " > Unknown distribution : $DIST" red
exit 2
;;
esac
}
# nagvis
function install_nagvis(){
cadre "Install nagvis addon" green
case $CODE in
REDHAT)
yum install -y $NAGVISYUMPKGS >> $TMP/shinken.install.log 2>&1
HTTPDUSER="apache"
HTTPDGROUP="apache"
HTTPDCONF="/etc/httpd/conf.d"
HTTPDINIT="/etc/init.d/httpd"
;;
DEBIAN)
cecho " > Installing prerequisites" green
apt-get update >> $TMP/shinken.install.log 2>&1
DEBIAN_FRONTEND=noninteractive apt-get install -y $NAGVISAPTPKGS >> $TMP/shinken.install.log 2>&1
HTTPDUSER="www-data"
HTTPDGROUP="www-data"
HTTPDCONF="/etc/apache2/conf.d"
HTTPDINIT="/etc/init.d/apache2"
;;
*)
cecho " > Unknown distribution : $DIST" red
exit 2
;;
esac
filename=$(echo $NAGVIS | awk -F"/" '{print $NF}')
folder=$(echo $filename | sed -e "s/\.tar\.gz//g")
cd $TMP