How to fully install Cacti on Ubuntu/Debian in a script way
Cacti is one of better monitoring tools to graph metrics based on RRDTool‘s data storage. So, I want to use it to monitor Petals ESB deployed in the cloud with Roboconf.
It can be easily installed on Ubuntu or Debian system through the package cacti
. But few information is asked during installation (password of the DB administrator user, password of the DB user for Cacti, the web-server to use, …). And a post-installation procedure is automatically launched at the first access to the web-application Cacti. This last point prohibits a full automatized installation of Cacti.
To be able to monitor a Petals ESB instance deployed in the cloud with Roboconf, Cacti must be fully installed in a script way. In this post, I’ll expose how I have get round the post-installation procedure using curl
to have a fully automatized installation of Cacti.
First, to install the package cacti
without to be prompted to enter asked information, I use the command debconf-set-selections
to set my default values that will be used during installation. Caution, in this example, the Cacti’s database will not be created during installation.
echo "cacti cacti/webserver select apache2" | debconf-set-selections
echo "cacti cacti/mysql/admin-pass password ${MySQL_0_MySQLRootPwd}" | debconf-set-selections
echo "cacti cacti/db/app-user string ${Cacti_DB_0_MySQLCactiUser}" | debconf-set-selections
echo "cacti cacti/mysql/app-pass password ${Cacti_DB_0_MySQLCactiPwd}" | debconf-set-selections
echo "cacti cacti/dbconfig-install boolean true" | debconf-set-selections
apt-get -y install cacti
service apache2 reload
Now, if you go to http://localhost/cacti
, you are redirected to the post-installation procedure, that can be executed in a script way using curl
as following:
COOKIE_FILE="/tmp/cacti-post-install-settings.cookie"
CSRF_MAGIC=curl -L --request GET "http://${ip}/cacti" -c ${COOKIE_FILE} | sed -n 's/.*name=.__csrf_magic.\s\+value="\(sid:[^"]*\).*/\1/p'
curl -L "http://${ip}/cacti/install/index.php" --referer "http://${ip}/cacti/install/" -b ${COOKIE_FILE} -c ${COOKIE_FILE} \
--data "__csrf_magic=${CSRF_MAGIC}" \
--data "step=1"
curl -L "http://${ip}/cacti/install/index.php" --referer "http://${ip}/cacti/install/index.php" -b ${COOKIE_FILE} -c ${COOKIE_FILE} \
--data "__csrf_magic=${CSRF_MAGIC}" \
--data "step=2" \
--data "install_type=1"
CSRF_MAGIC=curl -L "http://${ip}/cacti/install/index.php" --referer "http://${ip}/cacti/install/index.php" -b ${COOKIE_FILE} -c ${COOKIE_FILE} \
--data "__csrf_magic=${CSRF_MAGIC}" \
--data "step=3" \
--data-urlencode "path_rrdtool=/usr/bin/rrdtool" \
--data-urlencode "path_php_binary=/usr/bin/php" \
--data-urlencode "path_snmpwalk=/usr/bin/snmpwalk" \
--data-urlencode "path_snmpget=/usr/bin/snmpget" \
--data-urlencode "path_snmpbulkwalk=/usr/bin/snmpbulkwalk" \
--data-urlencode "path_snmpgetnext=/usr/bin/snmpgetnext" \
--data-urlencode "path_cactilog=/var/log/cacti/cacti.log" \
--data-urlencode "snmp_version=net-snmp" \
--data-urlencode "rrdtool_version=rrd-1.4.x" | sed -n 's/.*name=.__csrf_magic.\s\+value="\(sid:[^"]*\).*/\1/p'
curl -L "http://${ip}/cacti/index.php" --referer "http://${ip}/cacti/index.php" -b ${COOKIE_FILE} -c ${COOKIE_FILE} \
--data "__csrf_magic=${CSRF_MAGIC}" \
--data "action=login" \
--data "login_username=admin" \
--data "login_password=admin"
curl -L "http://${ip}/cacti/auth_changepassword.php" --referer "http://${ip}/cacti/auth_changepassword.php?ref=http://${ip}/cacti/index.php" -b ${COOKIE_FILE} -c ${COOKIE_FILE} \
--data "__csrf_magic=${CSRF_MAGIC}" \
--data "action=changepassword" \
--data-urlencode "password=${AdminPwd}" \
--data-urlencode "confirm=${AdminPwd}" \
--data-urlencode "ref=http://${ip}/cacti/index.php"
where ${ip}
is the host where Cacti is hosted, and ${AdminPwd}
is the password to set to the Cacti user admin
.
Chaining both script blocks you get an installation of Cacti fully automatized !
The Matthew Shepard Foundation runs Matthew’s Place For me it worked amazingly against the nipples