-
Notifications
You must be signed in to change notification settings - Fork 7
/
addclient.sh
executable file
·132 lines (107 loc) · 3.04 KB
/
addclient.sh
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
#!/bin/bash
#This line is messages for user
echo -en "In order to continue please add 'ansible' user to remote system\n"
echo -en "Also, please make sure ansible user in /etc/sudoers file with full privileges \n"
echo ""
echo -en "Please run the following command on remote system as root\n"
echo ""
echo -en "[root@localhost]# visudo\n"
echo ""
echo -en "Go to the line 99 and add the following\n "
echo ""
echo -en "ansible ALL=(ALL) NOPASSWD: ALL"
echo ""
echo ""
echo ""
echo ""
#This line prompts user if they added user
echo -en "Have you added ansible user to remote system? yes/no "
read ANSWER
#This line checks for user input if user said yes it will move on otherwise it will quit
if [ $ANSWER == "yes" ]
then
:
else
echo ""
echo -en "Please add ansible user to remote system and come back\n"
echo -en "Thank you\n"
echo ""
exit 1
fi
#This line asks for hostname of remote system
echo -en "Please enter your hostname: "
read HOSTNAME1
if [ -f $HOSTNAME1 ]
then
echo "The hostname exists"
exit 1
fi
#This line asks for customer id
echo -n "What is the customer ID?: "
read FOLDER
if [ -d $FOLDER ]
then
:
echo ""
echo "Folder exists moving on..."
echo ""
else
#This line creates a folder in objects/servers folder
mkdir /usr/local/nagios/etc/objects/servers/$FOLDER
echo ""
echo "##################################"
echo "Creating a new folder for customer"
echo "##################################"
echo ""
fi
# this line copies template to newclient
cp -rf /usr/local/nagios/etc/objects/servers/template /usr/local/nagios/etc/objects/servers/$FOLDER/$HOSTNAME1.cfg
echo -n "What is the IP? "
read IP
echo -n "What is the SSH Port?: "
read PORT
echo -en "Please enter root passwd for remote system once: "
read ROOTPASSWD
#This line checks if the remote host is up.
cd /usr/local/nagios/etc/objects/servers &> /dev/null
sed "s/172.16.0.23/$IP/g" /usr/local/nagios/etc/objects/servers/$FOLDER/$HOSTNAME1.cfg -i
cd /usr/local/nagios/etc/objects/servers/$FOLDER
sed "s/client1/$HOSTNAME1/g" /usr/local/nagios/etc/objects/servers/$FOLDER/$HOSTNAME1.cfg -i
cd - &> /dev/null
MESSAGE=$(fping $IP | awk '{print $3}' )
if [ $MESSAGE == "alive" ]
then
echo "The host is alive\n"
sleep 2
echo "moving on"
else
echo "The host seems to be down\n"
echo "Please make sure the host is up\n"
sleep 3
echo 1
fi
sshpass -p $ROOTPASSWD ssh-copy-id "root@$IP -p $PORT" &> /dev/null
#This line is for ansible only
#This line creates an inventory file for ansible
echo $IP:$PORT > /etc/ansible/$IP
chmod +x /etc/ansible/$IP
echo -en "Please wait nrpe is being installed"
ansible-playbook -i /etc/ansible/$IP /etc/ansible/nrpe_install.yml
echo ""
echo "The host successfully added please check nagios web page"
echo ""
echo -en "Would you like to add another host yes/no? :"
read ANSWER
if [ $ANSWER == "yes" ]
then
exit 0
else
echo "It was pleasure working with you\n"
echo "Even though I am a machine\n"
echo Bye
exit 1
fi
echo "Please enter CTRL +C to quit"
echo "################################################"
echo ""
bash addclient.sh