forked from shinken-solutions/shinken
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·3531 lines (3170 loc) · 112 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, naparuba@gmail.com
# Gerhard Lausser, Gerhard.Lausser@consol.de
# David GUENAULT, dguenault@monitoring-fr.org
# Romain FORLOT, rforlot@yahoo.com
#
#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
function remove(){
cadre "Removing shinken" green
skill
manageparameters "quiet"
if [ -d "$TARGET" ]
then
cecho " > Removing $TARGET" green
rm -Rf $TARGET
fi
if [ -d "$ETC" ]
then
cecho " > Removing $ETC" green
rm -Rf $ETC
fi
if [ -h "/etc/default/shinken" ]
then
cecho " > Removing defaults" green
rm -Rf /etc/default/shinken
fi
if [ -f "/etc/init.d/shinken" ] || [ -f ${SYSTEMDPATH}lib/systemd/system/shinken-arbiter.service ]
then
cecho " > Removing startup scripts" green
case $INIT in
init)
disable_service shinken
rm -f /etc/init.d/shinken* >> ${LOGFILE} 2>&1
;;
systemd)
systemctl disable $SYSTEMDSERVICES >> ${LOGFILE} 2>&1
rm -f ${SYSTEMDPATH}lib/systemd/system/shinken* >> ${LOGFILE} 2>&1
systemctl --system daemon-reload
;;
esac
fi
# Remove sudo file used for shinken
rm -f /etc/sudoers.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
manage_service npcd stop >> ${LOGFILE} 2>&1
disable_service npcd
rm -f /etc/init.d/npcd >> ${LOGFILE} 2>&1
rm -f /etc/${WEBSERVER}/conf.d/pnp4nagios.conf >> ${LOGFILE} 2>&1
manage_service ${WEBSERVER} restart >> ${LOGFILE} 2>&1
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
manage_service ${WEBSERVER} restart
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
rm -f /etc/${WEBSERVER}/conf.d/nagvis.conf >> ${LOGFILE} 2>&1
manage_service ${WEBSERVER} restart
else
cecho " > Aborting uninstallation of nagvis" yellow
fi
fi
return 0
}
function disable_service(){
service=$1
case $CODE in
REDHAT)
chkconfig $service off >> ${LOGFILE} 2>&1
chkconfig --del $service >> ${LOGFILE} 2>&1
;;
Fedora)
systemctl disable ${service}.service >> ${LOGFILE} 2>&1
systemctl --system daemon-reload >> ${LOGFILE} 2>&1
;;
DEBIAN)
update-rc.d -f $service remove >> ${LOGFILE} 2>&1
;;
esac
}
function enable_service(){
service=$1
case $CODE in
REDHAT)
chkconfig --add $service >> ${LOGFILE} 2>&1
chkconfig $service on >> ${LOGFILE} 2>&1
;;
Fedora)
systemctl --system daemon-reload >> ${LOGFILE} 2>&1
systemctl enable ${service}.service >> ${LOGFILE} 2>&1
;;
DEBIAN)
update-rc.d $service defaults >> ${LOGFILE} 2>&1
;;
esac
}
function manage_service() {
service=$1
operation=$2
case $CODE in
REDHAT)
service $service $operation >> ${LOGFILE} 2>&1
;;
Fedora)
systemctl $operation ${service}.service >> ${LOGFILE} 2>&1
;;
DEBIAN)
/etc/init.d/${service} $operation >> ${LOGFILE} 2>&1
;;
esac
}
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 >> ${LOGFILE} 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(){
cecho " > Stopping Shinken" green
case $INIT in
init)
/etc/init.d/shinken stop >> ${LOGFILE} 2>&1
;;
systemd)
systemctl stop $SYSTEMDSERVICES >> ${LOGFILE} 2>&1
systemctl status $SYSTEMDSERVICES >> ${LOGFILE} 2>&1
;;
esac
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 sstart() {
cecho " > Starting shinken" green
case $INIT in
init)
/etc/init.d/shinken start >> ${LOGFILE} 2>&1
;;
systemd)
systemctl --system daemon-reload
systemctl start $SYSTEMDSERVICES >> ${LOGFILE} 2>&1
systemctl status $SYSTEMDSERVICES >> ${LOGFILE} 2>&1
;;
*)
cecho " > Your init system aren't supported in shinken for now." red
exit 2
;;
esac
}
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' $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 -r -s /bin/bash $SKUSER -m
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
shift
package="$*"
if [ "$type" == "python" ]
then
PYEI="easy_install"
$PYEI $package >> ${LOGFILE} 2>&1
return $?
elif [ "$type" = "pkg" ]
then
case $CODE in
REDHAT|Fedora)
yum install -y $package >> ${LOGFILE} 2>&1
if [ $? -ne 0 ]
then
return 2
fi
;;
DEBIAN)
apt-get update >> ${LOGFILE} 2>&1
apt-get --allow-unauthenticated --force-yes install -y $package >> ${LOGFILE} 2>&1
if [ $? -ne 0 ]
then
return 2
fi
;;
esac
fi
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 gawk grep python bash sudo"
for b in $bins
do
rb=$(which $b >> ${LOGFILE} 2>&1)
if [ $? -eq 0 ]
then
cecho " > Checking for $b: OK" green
else
cecho " > Checking for $b: NOT FOUND. Installing it!" red
installpkg pkg $b
fi
done
# distro prereq
case $CODE in
REDHAT)
case $VERS in
[5-6])
PACKAGES=$YUMPKGS
QUERY="rpm -q "
cd $TMP
$QUERY $EPELNAME >> ${LOGFILE} 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 >> ${LOGFILE} 2>&1
if [ $? -ne 0 ]
then
cecho " > Error while trying to download EPEL repositories" red
exit 2
fi
rpm -Uvh ./$EPELPKG >> ${LOGFILE} 2>&1
find /etc/pki/rpm-gpg -name "RPM-GPG-KEY-EPEl*" -exec rpm --import {} \;
fi
else
cecho " > $EPELPKG already installed" green
fi
;;
*)
cecho " > Unsupported RedHat/CentOs version" red
exit 2
;;
esac
;;
Fedora)
case $VERS in
16|17|18)
PACKAGES=$YUMPKGS
QUERY="rpm -q "
;;
*)
cecho " > Unsupported Fedora version" red
exit 2
;;
esac
;;
DEBIAN)
PACKAGES=$APTPKGS
if [ $SKIPPREREQUISITES -ne 1 ]
then
apt-get update >> ${LOGFILE} 2>&1
fi
QUERY="debinstalled "
;;
esac
if [ $SKIPPREREQUISITES -eq 1 ]
then
cecho " > SKIPPREQUISITES enabled: won't install $PACKAGES" red
else
cecho " > Installing $PACKAGES " yellow
installpkg pkg $PACKAGES
if [ $? -ne 0 ]
then
cecho " > Error while trying to install $PACKAGES" red
exit 2
fi
fi
# python prereq
export PY="python"
export PYEI="easy_install"
if [ "$CODE" = "REDHAT" ]
then
PYLIBS=$PYLIBSRHEL6
elif [ "$CODE" = "Fedora" ]
then
case $VERS in
16|17)
PYLIBS=$PYLIBS
;;
esac
elif [ "$CODE" == "DEBIAN" ]
then
PYLIBS=$PYLIBSDEB
fi
# this is a fix for MySQL-python complainig about outdated version of distribute
cecho " > Installing distribute" green
easy_install -U distribute >> ${LOGFILE} 2>&1
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 >> ${LOGFILE} 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
installpkg python $module >> ${LOGFILE} 2>&1
if [ $? -ne 0 ]
then
cecho " > $type package $package doesn't installed properly. Run 'easy_install $package' manually" red
cecho " > and try to figure out what's is going on."
fi
fi
else
cecho " > Module $module found." green
fi
done
if [ $MANAGEPYRO == 1 ]
then
cecho " > Installing managed python (experimental) " green
easy_install pip
yes | pip uninstall Pyro
yes | pip uninstall Pyro4
pyroset
$PYEI "$PYRO"
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 >> ${LOGFILE} 2>&1
cd shinken
cecho " > Switching to version $VERSION" green
git checkout $VERSION >> ${LOGFILE} 2>&1
export src=$TMP/shinken
# clean up .git folder
rm -Rf .git
}
function register(){
cadre "API key registration" green
if [ -f $ETC/apikey ]
then
exist=$(cat $ETC/apikey)
if [ $? -ne 0 ]
then
exist=""
fi
else
exist=""
fi
if [ -z "$exist" ]
then
cecho " > Api key not found" yellow
cread " > Do you already have an api key? [y|n] " green "y" "y n"
if [ "$readvalue" == "Y" ] || [ "$readvalue" == "y" ]
then
creads " --> Please Provide your apikey" yellow
if [ ! -z "$readvalue" ]
then
cecho " --> apikey saved " green
echo "$readvalue" > $ETC/apikey
else
cecho " --> api key must not be empty" red
register
fi
return 0
fi
else
cecho " > Found api key" green
exit 0
fi
cecho " > You must register on community.shinken-monitoring.org in order to use online pack management" yellow
cread " --> Do you want to register? [Y|n] " yellow "Y" "y n"
if [ "$readvalue" == "N" ] || [ "$readvalue" == "n" ]
then
cecho " --> api key not configured. You will have to do it manualy. See: http://www.shinken-monitoring.org/wiki/packs/start" red
return 0
fi
creads " -->login: " yellow
login=$readvalue
creads " --> password: " yellow
pass1=$readvalue
creads " --> confirm password: " yellow
pass2=$readvalue
if [ "$pass1" != "$pass2" ]
then
cecho " ----> Password confirmation does not match!" red
register
else
pass=$pass1
if [ -z "$pass" ]
then
cecho " ----> Password must not be empty" red
register
fi
fi
creads " --> Email" yellow
email=$readvalue
cecho " > trying to register " yellow
result=$($TARGET/bin/shinken-packs -r -l $login -P $pass -e $email | grep "^OK")
if [ ! -z "$result" ]
then
creads " --> Registration success. Please look at your email and click in the link in it to validate your account (Hit ENTER when done)" green
cecho " ----> Getting key" green
apikey=$($TARGET/bin/shinken-packs -g -l $login -P $pass | grep "api key is" | awk '{print $5}')
if [ -z "$apikey" ]
then
cecho " ------> There was a problem getting your api key!" red
cecho " ------> Yous should register manualy at http://community.shinken-monitoring.org" red
return 1
else
cecho " ------> Registration success" green
echo $apikey > $ETC/apikey
apikey=$(cat $ETC/apikey)
cd $ETC
sed -i "s#api_key=.*#api_key="$apikey"#g" skonf.cfg
return 0
fi
else
cecho " --> Registration failed!" red
register
fi
return 0
}
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
sed -i "s#__ETC__#$ETC#g" $f
done
# relocate nagios plugin path
cecho " > relocate nagios plugin path" green
sed -i "s#/usr/lib/nagios/plugins#$LIBEXEC#g" $ETC/resource.cfg
sed -i "s#/usr/local/shinken/libexec#$LIBEXEC#g" $ETC/resource.cfg
# relocate default /usr/local/shinken path
if [ "$TARGET" != "/usr/local/shinken" ]
then
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#/usr/local/shinken#'$TARGET'#g' "$fic"
done
fi
# do the same for etc dir if etc dir does not reside beside target
if [ "$TARGET/etc" != "$ETC" ]
then
cd $ETC
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#/usr/local/shinken#'$TARGET'#g' "$fic"
done
cd $TARGET
fi
# set some directives
cadre "Set some configuration directives" green
directives="workdir=$TARGET/var user=$SKUSER shinken_user=$SKUSER group=$SKGROUP shinken_group=$SKGROUP"
for fic in $(ls -1 $ETC/*.ini $ETC/skonf.cfg)
do
cecho " > Processing $fic" green;
setdirectives "$directives" $fic $TARGET
done
directives="workdir=$TARGET/var shinken_user=$SKUSER shinken_group=$SKGROUP local_log=$TARGET/var/arbiter.log lock_file=$TARGET/var/arbiter.pid"
for fic in $(ls -1 $ETC/nagios*cfg)
do
cecho " > Processing $fic" green;
setdirectives "$directives" $fic $TARGET
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='$ETC'#g' -e 's#VAR\=\(.*\)$#VAR='$TARGET'/var#g' -e 's#BIN\=\(.*\)$#BIN='$TARGET'/bin#g' > $TARGET/bin/default/shinken
rm $TARGET/bin/default/shinken.in
# relocate init file
sed -i -e "s#\#export PYTHONPATH=.*#export PYTHONPATH="$TARGET"#g" $TARGET/bin/init.d/shinken
# relocate skonf.cfg
cd $ETC
if [ $USEPROXY -eq 1 ]
then
sed -i "s#http_proxy=.*$#htt_proxy="$http_proxy"#g" skonf.cfg
fi
sed -i "s#/etc/shinken#"$ETC"#g" skonf.cfg
sed -i "s#/tmp#"$TMP"#g" skonf.cfg
sed -i "s#/var/lib/shinken/share#"$TARGET"/share#g" skonf.cfg
}
function fix(){
cadre "Applying various fixes" green
# fix the htpasswd.users file path for WEBUI authentication
export PYTHONPATH=$TARGET
export PY="$(pythonver)"
result=$($PY $TARGET/install.d/tools/skonf.py -f $ETC/shinken-specific.cfg -a setparam -o module -r "module_name=Apache_passwd" -d "passwd" -v "$ETC/htpasswd.users")
cecho " > $result" green
cecho " > Make files permissions and owners good" green
[ -f /etc/init.d/shinken ] && chmod +x /etc/init.d/shinken
chmod +x $TARGET/bin/init.d/shinken
chown -R $SKUSER:$SKGROUP $TARGET
chown -R $SKUSER:$SKGROUP $ETC
chmod -R g+w $TARGET
chmod -R g+w $ETC
cecho " > Fix /etc/sudoers file for shinken integration" green
cp /etc/sudoers /etc/sudoers.$(date +%Y%m%d%H%M%S)
sed -i "s/^Defaults.*requiretty/#&/g" /etc/sudoers
cecho " > Add Shinken entry for skonf in sudoers" green
echo "$SKUSER ALL=(ALL) NOPASSWD: /usr/bin/nmap" >> /etc/sudoers.d/shinken
chmod u=r,g=r,o= /etc/sudoers.d/shinken
[ $? -ne 0 ] && cecho "$DIST isn't supported, you must fix sudo permission at your own !!!" red
}
function enable_initd(){
cecho " > Installing startup scripts" green
case $INIT in
init)
cp $TARGET/bin/init.d/shinken* /etc/init.d/
cecho " > Enabling $DIST startup script" green
enable_service shinken
;;
systemd)
cp -f "$myscripts"/for_fedora/systemd/* ${SYSTEMDPATH}lib/systemd/system
# Fix path to daemon in service file for systemd
sed -i -e 's/sbin/local\/shinken\/bin/' -e 's/etc\/shinken/usr\/local\/shinken\/etc/g' ${SYSTEMDPATH}lib/systemd/system/shinken*
sed -i -e 's/Type=forking/&\nWorkingDirectory=\/usr\/local\/shinken\/shinken/g' ${SYSTEMDPATH}lib/systemd/system/shinken-arbiter
cecho " > Enabling $DIST startup script" green
enable_service shinken-arbiter
enable_service shinken-broker
enable_service shinken-poller
enable_service shinken-reactionner
enable_service shinken-receiver
enable_service shinken-scheduler
;;
*)
cecho " > Error! your init system isn't support by shinken for now." red
;;
esac
}
function cleanuptarget(){
# clean up unnecessary files and folders
if [ "$TARGET" == "/" ]
then
cecho " > Invalid target folder" red
exit 2
fi
if [ -z "$TARGET" ]
then
cecho " > Invalid target folder" red
exit 2
fi
cd $TARGET
rm -Rf test
rm -Rf windows
rm -Rf clean.sh
rm -Rf for_fedora
rm -Rf for_packages
# rm -Rf install install.d
rm -Rf MANIFEST.in setup.py
rm -Rf $ETC/*windows*
cp $ETC/shinken-specific.cfg $ETC/shinken-specific.cfg.orig
}
function manageparameters(){
if [ ! -f "$HOME/.shinken" ]
then
touch $HOME/.shinken
chmod +x $HOME/.shinken
if [ "$1" != "quiet" ]
then
echo "ETC=$ETC" >> $HOME/.shinken
echo "VAR=$VAR" >> $HOME/.shinken
echo "LIBEXEC=$LIBEXEC" >> $HOME/.shinken
echo "TARGET=$TARGET" >> $HOME/.shinken
fi
else
OLDIFS=$IFS
IFS=$'\n'
cecho " > Found installation parameters" yellow
for l in $(cat $HOME/.shinken)
do
cecho " --> $l" yellow
done
IFS=$OLDIFS
if [ "$1" != "quiet" ]
then
cread " > Do you want to reuse those parameters? " "yellow" "y" "y n"
else
readvalue="y"
fi
if [ "$readvalue" == "y" ]
then
for l in $(cat $HOME/.shinken)
do
export $l
done
else
rm -f $HOME/.shinken
touch $HOME/.shinken
chmod +x $HOME/.shinken
echo "ETC=$ETC" >> $HOME/.shinken
echo "VAR=$VAR" >> $HOME/.shinken
echo "LIBEXEC=$LIBEXEC" >> $HOME/.shinken
echo "TARGET=$TARGET" >> $HOME/.shinken
fi
fi
}
function sinstall(){
#cecho "Installing shinken" green
manageparameters
check_distro
check_exist
prerequisites
create_user
# control if target parent folder exist
parent=$(echo $TARGET | sed -e "s#"$(echo $TARGET | awk -F/ '{print $NF}')"##g")
if [ ! -d $parent ]
then
mkdir -p $parent
fi
if [ ! -d $ETC ]
then
mkdir -p $ETC
fi
if [ ! -d $TARGET ]
then
mkdir -p $TARGET
fi
cp -Rf "$myscripts"/* $TARGET/
if [ "$TARGET" == "/" ] || [ -z "$TARGET" ]
then
cecho " ALERT! TARGET should not be empty or /" red
exit 2
fi
if [ "$TARGET/etc" != "$ETC" ]
then
rm -Rf $TARGET/etc
cp -Rf "$myscripts"/etc/* $ETC/
fi
# We want to copy the src/share into the var
if [ ! -d $TARGET/var/share ]
then
mkdir -p $TARGET/var/share
cp -Rf "$myscripts"/share/* $TARGET/var/share
fi
cleanuptarget
relocate
ln -s $TARGET/bin/default/shinken /etc/default/shinken
mkdir -p $TARGET/var/archives
enableretention
enable_initd
if [[ $NOMONGO -eq 1 ]]
then
cecho " > Skip mongo installation" green
else
install_mongodb
fi
if [ "$LOGSTORE" == "mongo" ]
then
enablemongologs
fi
fix
sstart
cecho "+------------------------------------------------------------------------------" green
cecho "| Shinken is now installed on your server " green
cecho "| The install location is: $TARGET" green
cecho "| The configuration folder is: $ETC" green
cecho "| " green
cecho "| The Web Interface is available at: http://localhost:7767" green
cecho "| The default credentials for the webui are admin/admin" green
cecho "| " green
cecho "| You can now learn how to configure shinken at: http://www.shinken-monitoring.org/wiki" green
cecho "+------------------------------------------------------------------------------" green
echo ""
cecho "Do not forget to allow localhost to browse the entire snmp tree. Sample configuration" yellow
cecho "use snmp checks and the plugins should be able to access local snmp tree." yellow
cecho "For testing purpose you could modify your snmpd configuration this way :" yellow
echo ""
cecho "Debian :" yellow
cecho " edit /etc/snmp/snmpd.conf and replace the following lines :" yellow
cecho " view systemonly included .1.3.6.1.2.1.1" yellow
cecho " view systemonly included .1.3.6.1.2.1.25.1" yellow
cecho " by this one : " yellow
cecho " view systemonly included .1" yellow
echo ""
cecho "RedHat/CentOS :" yellow
cecho " edit /etc/snmp/snmpd.conf and replace the following lines :" yellow
cecho " view systemview included .1.3.6.1.2.1.1" yellow
cecho " view systemview included .1.3.6.1.2.1.25.1" yellow
cecho " by this one : " yellow
cecho " view systemview included .1" yellow
}
########################
### BACKUP FUNCTIONS ###
########################
function backup(){
cadre "Backup shinken platform" green
manageparameters "quiet" > /dev/null 2>&1
cecho " > Stop shinken" green
skill
if [ -f /etc/init.d/npcd ]
then
cecho " > Stop npcd" green
manage_service npcd stop > /dev/null 2>&1
fi
if [ ! -e $BACKUPDIR ]
then
mkdir $BACKUPDIR
fi
mkdir -p $BACKUPDIR/bck-shinken.$DATE/etc
mkdir -p $BACKUPDIR/bck-shinken.$DATE/libexec
mkdir -p $BACKUPDIR/bck-shinken.$DATE/var
# Sugg:
# Add: cp -Rfp $TARGET/bin $BACKUPDIR/bck-shinken.$DATE/ line to backup bin
cecho " > Backup shinken" green
cecho " --> Backup shinken/etc" green
cp -Rfp $ETC/* $BACKUPDIR/bck-shinken.$DATE/etc
cecho " --> Backup shinken/libexec" green
cp -Rfp $LIBEXEC/* $BACKUPDIR/bck-shinken.$DATE/libexec
cecho " --> Backup shinken/var" green
cp -Rfp $TARGET/var/* $BACKUPDIR/bck-shinken.$DATE/var
if [ -d $NAGVISPREFIX ]
then
cecho " > Backup nagvis" green
mkdir -p $BACKUPDIR/bck-shinken.$DATE/nagvis
cecho " --> Backup nagvis/share/userfiles" green
cp -Rfp $NAGVISPREFIX/share/userfiles $BACKUPDIR/bck-shinken.$DATE/nagvis/
cecho " --> Backup nagvis/etc" green
cp -Rfp $NAGVISPREFIX/etc $BACKUPDIR/bck-shinken.$DATE/nagvis/
fi