2014-04-13 17:15:55 +02:00
|
|
|
#!/bin/sh
|
2014-04-12 11:35:18 +02:00
|
|
|
ICINGA2PKIDIR=@CMAKE_INSTALL_FULL_DATADIR@/icinga2/pki
|
|
|
|
ICINGA2CONFIG=@CMAKE_INSTALL_FULL_SYSCONFDIR@/icinga2
|
|
|
|
|
2014-05-12 14:46:02 +02:00
|
|
|
name=`hostname --fqdn`
|
|
|
|
|
|
|
|
echo "Agent name: $name"
|
|
|
|
|
2014-04-12 11:35:18 +02:00
|
|
|
if [ -n "$1" ]; then
|
2014-05-12 14:46:02 +02:00
|
|
|
if [ ! -e $ICINGA2CONFIG/pki/$name.key ]; then
|
2014-04-12 11:35:18 +02:00
|
|
|
echo "You haven't generated a private key for this Icinga 2 instance"
|
|
|
|
echo "yet. Please run this script without any parameters to generate a key."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -e "$1" ]; then
|
|
|
|
echo "The specified key bundle does not exist."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-04-13 19:24:22 +02:00
|
|
|
if ! base64 -d $1 >/dev/null 2>&1; then
|
2014-04-13 12:44:18 +02:00
|
|
|
echo "The bundle file is invalid or corrupted."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-04-12 12:56:35 +02:00
|
|
|
while true; do
|
2014-04-13 01:59:25 +02:00
|
|
|
echo -n "Are you setting up a new master instance? [n] "
|
|
|
|
if ! read master; then
|
2014-04-12 12:56:35 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-04-13 01:59:25 +02:00
|
|
|
if [ "$master" = "y" -o "$master" = "n" -o -z "$master" ]; then
|
2014-04-12 12:56:35 +02:00
|
|
|
break
|
|
|
|
fi
|
2014-04-13 01:59:25 +02:00
|
|
|
|
|
|
|
echo "Please enter 'y' or 'n'."
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -z "$master" ]; then
|
|
|
|
master=n
|
|
|
|
fi
|
|
|
|
|
|
|
|
upstream_name=""
|
|
|
|
|
|
|
|
if [ "$master" = "n" ]; then
|
|
|
|
while true; do
|
2014-04-13 17:32:38 +02:00
|
|
|
echo -n "Master Icinga instance name: "
|
2014-04-13 01:59:25 +02:00
|
|
|
if ! read upstream_name; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$upstream_name" ]; then
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Please enter an instance name."
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2014-05-12 14:46:02 +02:00
|
|
|
listener_port=""
|
|
|
|
|
2014-04-13 01:59:25 +02:00
|
|
|
while true; do
|
2014-05-12 14:46:02 +02:00
|
|
|
echo -n "Which TCP port should the agent listen on? [5665] "
|
|
|
|
if ! read listener_port; then
|
2014-04-13 01:59:25 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-05-12 14:46:02 +02:00
|
|
|
break
|
2014-04-13 01:59:25 +02:00
|
|
|
done
|
|
|
|
|
2014-05-12 14:46:02 +02:00
|
|
|
if [ -z "$listener_port" ]; then
|
|
|
|
listener_port=5665
|
2014-04-13 01:59:25 +02:00
|
|
|
fi
|
|
|
|
|
2014-04-13 13:48:51 +02:00
|
|
|
upstream_connect=n
|
2014-04-13 01:59:25 +02:00
|
|
|
|
2014-04-13 13:48:51 +02:00
|
|
|
if [ "$master" = "n" ]; then
|
2014-04-13 01:59:25 +02:00
|
|
|
while true; do
|
2014-04-13 17:32:38 +02:00
|
|
|
echo -n "Do you want this agent instance to connect to the master instance? [y] "
|
2014-04-13 13:48:51 +02:00
|
|
|
if ! read upstream_connect; then
|
2014-04-13 01:59:25 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-04-13 13:48:51 +02:00
|
|
|
if [ "$upstream_connect" = "y" -o "$upstream_connect" = "n" -o -z "$upstream_connect" ]; then
|
2014-04-13 01:59:25 +02:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
2014-04-13 13:48:51 +02:00
|
|
|
echo "Please enter 'y' or 'n'."
|
2014-04-13 01:59:25 +02:00
|
|
|
done
|
|
|
|
|
2014-04-13 13:48:51 +02:00
|
|
|
if [ -z "$upstream_connect" ]; then
|
|
|
|
upstream_connect=y
|
|
|
|
fi
|
2014-04-13 01:59:25 +02:00
|
|
|
|
2014-04-13 13:48:51 +02:00
|
|
|
if [ "$upstream_connect" = "y" ]; then
|
2014-05-12 14:46:02 +02:00
|
|
|
echo -n "Master instance IP address/hostname [$upstream_name]: "
|
|
|
|
if ! read upstream_host; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$upstream_host" ]; then
|
|
|
|
upstream_host=$upstream_name
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo -n "Master instance port [5665]: "
|
|
|
|
if ! read upstream_port; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -z "$upstream_port" ]; then
|
|
|
|
upstream_port=5665
|
|
|
|
fi
|
2014-04-13 13:48:51 +02:00
|
|
|
fi
|
2014-04-13 01:59:25 +02:00
|
|
|
fi
|
|
|
|
|
2014-04-12 11:51:18 +02:00
|
|
|
echo "Installing the certificate bundle..."
|
2014-05-12 14:46:02 +02:00
|
|
|
base64 -d < $1 | tar -C $ICINGA2CONFIG/pki/ -zx || exit 1
|
|
|
|
chown @ICINGA2_USER@:@ICINGA2_GROUP@ $ICINGA2CONFIG/pki/* || exit 1
|
2014-04-12 11:35:18 +02:00
|
|
|
|
2014-05-12 14:46:02 +02:00
|
|
|
echo "Setting up api.configuration..."
|
|
|
|
cat >$ICINGA2CONFIG/features-available/api.conf <<AGENT
|
2014-04-12 11:35:18 +02:00
|
|
|
/**
|
2014-05-12 14:46:02 +02:00
|
|
|
* The API listener is used for distributed monitoring setups.
|
2014-04-12 11:35:18 +02:00
|
|
|
*/
|
|
|
|
|
2014-05-12 14:46:02 +02:00
|
|
|
object ApiListener "api" {
|
|
|
|
cert_path = SysconfDir + "/icinga2/pki/" + NodeName + ".crt"
|
|
|
|
key_path = SysconfDir + "/icinga2/pki/" + NodeName + ".key"
|
|
|
|
ca_path = SysconfDir + "/icinga2/pki/ca.crt"
|
|
|
|
|
|
|
|
bind_port = "$listener_port"
|
|
|
|
}
|
|
|
|
|
|
|
|
object Endpoint NodeName {
|
|
|
|
host = NodeName
|
|
|
|
}
|
|
|
|
|
|
|
|
object Zone ZoneName {
|
2014-04-13 01:59:25 +02:00
|
|
|
AGENT
|
|
|
|
|
|
|
|
if [ "$upstream_connect" = "y" ]; then
|
2014-05-12 14:46:02 +02:00
|
|
|
cat >>$ICINGA2CONFIG/features-available/api.conf <<AGENT
|
|
|
|
parent = "$upstream_name"
|
2014-04-13 01:59:25 +02:00
|
|
|
AGENT
|
|
|
|
fi
|
2014-04-12 12:56:35 +02:00
|
|
|
|
2014-05-12 14:46:02 +02:00
|
|
|
cat >>$ICINGA2CONFIG/features-available/api.conf <<AGENT
|
|
|
|
endpoints = [ NodeName ]
|
2014-04-12 11:35:18 +02:00
|
|
|
}
|
2014-05-12 14:46:02 +02:00
|
|
|
|
2014-04-12 11:35:18 +02:00
|
|
|
AGENT
|
|
|
|
|
2014-05-12 14:46:02 +02:00
|
|
|
if [ "$upstream_connect" = "y" ]; then
|
|
|
|
cat >>$ICINGA2CONFIG/features-available/api.conf <<AGENT
|
|
|
|
object Endpoint "$upstream_name" {
|
|
|
|
host = "$upstream_host"
|
|
|
|
port = "$upstream_port"
|
|
|
|
}
|
|
|
|
|
|
|
|
object Zone "$upstream_name" {
|
|
|
|
endpoints = [ "$upstream_name" ]
|
|
|
|
}
|
|
|
|
AGENT
|
|
|
|
fi
|
|
|
|
|
2014-05-12 15:55:04 +02:00
|
|
|
sed -i "s/NodeName = \"localhost\"/NodeName = \"$name\"/" /etc/icinga2/constants.conf
|
|
|
|
|
2014-05-12 14:46:02 +02:00
|
|
|
echo "Enabling API feature..."
|
|
|
|
@CMAKE_INSTALL_FULL_SBINDIR@/icinga2-enable-feature api
|
2014-04-12 11:35:18 +02:00
|
|
|
|
2014-04-13 17:32:38 +02:00
|
|
|
if [ ! -e "@CMAKE_INSTALL_FULL_SYSCONFDIR@/monitoring" ]; then
|
|
|
|
ln -s $ICINGA2CONFIG/conf.d/hosts/localhost @CMAKE_INSTALL_FULL_SYSCONFDIR@/monitoring
|
|
|
|
fi
|
|
|
|
|
2014-04-13 13:49:38 +02:00
|
|
|
if [ "$master" = "n" ]; then
|
|
|
|
echo "Disabling notification feature..."
|
|
|
|
@CMAKE_INSTALL_FULL_SBINDIR@/icinga2-disable-feature notification
|
|
|
|
fi
|
2014-04-12 11:55:10 +02:00
|
|
|
|
2014-04-12 11:51:18 +02:00
|
|
|
echo ""
|
2014-04-12 11:35:18 +02:00
|
|
|
echo "The key bundle was installed successfully and the agent component"
|
|
|
|
echo "was enabled. Please make sure to restart Icinga 2 for these changes"
|
|
|
|
echo "to take effect."
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2014-05-12 14:46:02 +02:00
|
|
|
mkdir -p $ICINGA2CONFIG/pki
|
2014-04-12 11:35:18 +02:00
|
|
|
chmod 700 $ICINGA2CONFIG/pki
|
|
|
|
chown @ICINGA2_USER@:@ICINGA2_GROUP@ $ICINGA2CONFIG/pki || exit 1
|
|
|
|
|
2014-05-12 14:46:02 +02:00
|
|
|
if [ -e $ICINGA2CONFIG/pki/$name.crt ]; then
|
|
|
|
echo "You already have agent certificates in $ICINGA2CONFIG/pki/"
|
2014-04-12 11:35:18 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-05-12 14:46:02 +02:00
|
|
|
REQ_COMMON_NAME="$name" KEY_DIR="$ICINGA2CONFIG/pki/" openssl req -config $ICINGA2PKIDIR/openssl-quiet.cnf -new -newkey rsa:4096 -keyform PEM -keyout $ICINGA2CONFIG/pki/$name.key -outform PEM -out $ICINGA2CONFIG/pki/$name.csr -nodes && \
|
|
|
|
chmod 600 $ICINGA2CONFIG/pki/$name.key
|
2014-04-12 11:35:18 +02:00
|
|
|
|
2014-04-13 01:59:25 +02:00
|
|
|
echo "Please sign the following CSR using the Agent CA:"
|
2014-04-12 11:35:18 +02:00
|
|
|
echo ""
|
|
|
|
|
2014-05-12 14:46:02 +02:00
|
|
|
cat $ICINGA2CONFIG/pki/$name.csr
|
2014-04-12 11:35:18 +02:00
|
|
|
|
|
|
|
echo ""
|
|
|
|
|
|
|
|
echo "You can use the icinga2-sign-key command to sign the CSR. Once signed the"
|
|
|
|
echo "key bundle can be installed using $0 <bundle>."
|
|
|
|
exit 0
|