<commit_before>#!/bin/sh -e

set -x

# Install required dependencies
apt-get -y install python-setuptools python-pip build-essential python-dev
apt-get -y install mongodb-server rabbitmq-server apache2 libapache2-mod-wsgi

# Configure MongoDB
grep -q smallfiles /etc/mongodb.conf || echo "smallfiles = true" | tee -a /etc/mongodb.conf
service mongodb restart

# Configure RabbitMQ
/usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management
/usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_stomp
service rabbitmq-server restart
wget -qO /var/tmp/rabbitmqadmin http://guest:guest@localhost:55672/cli/rabbitmqadmin && chmod +x /var/tmp/rabbitmqadmin
/var/tmp/rabbitmqadmin declare exchange name=alerts type=fanout durable=true

# Install and configure Alerta
pip install alerta
mkdir -p /etc/alerta
cp /vagrant/files/alerta.conf /etc/alerta/alerta.conf
cp /vagrant/files/upstart-alerta.conf /etc/init/alerta.conf
initctl reload-configuration alerta
service alerta restart

# Configure Apache web server
mkdir -p /var/www/alerta
cp /vagrant/files/alerta-api.wsgi /var/www/alerta/alerta-api.wsgi
cp /vagrant/files/httpd-alerta-api.conf /etc/apache2/sites-available/alerta-api
a2ensite alerta-api

cp /vagrant/files/alerta-dashboard.wsgi /var/www/alerta/alerta-dashboard.wsgi
cp /vagrant/files/httpd-alerta-dashboard.conf /etc/apache2/sites-available/alerta-dashboard
PYTHON_ROOT_DIR=`python -c "import alerta; print(alerta.__dict__['__path__'][0])"`
sed -i "s#@STATIC@#$PYTHON_ROOT_DIR#" /etc/apache2/sites-available/alerta-dashboard
a2ensite alerta-dashboard

chmod 0777 /var/log/alerta && chgrp www-data /var/log/alerta
a2dissite 000-default
echo "ServerName localhost" >> /etc/apache2/apache2.conf
service apache2 reload

# Generate test alerts
cp /vagrant/files/create-alerts.sh /var/tmp/create-alerts.sh
chmod +x /var/tmp/create-alerts.sh && /var/tmp/create-alerts.sh

# Clean-up
mongo monitoring --eval 'db.heartbeats.remove()'<commit_msg>update alerta.sh<commit_after>#!/bin/sh -e

set -x

# Install required dependencies
apt-get -y install python-setuptools python-pip build-essential python-dev
apt-get -y install mongodb-server rabbitmq-server apache2 libapache2-mod-wsgi

# Configure MongoDB
grep -q smallfiles /etc/mongodb.conf || echo "smallfiles = true" | tee -a /etc/mongodb.conf
service mongodb restart

# Configure RabbitMQ
/usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management
service rabbitmq-server restart

# Install and configure Alerta
pip install alerta
groupadd alerta
useradd -g alerta alerta

# Configure Apache web server
wget -qO /etc/apache2/sites-available/alerta https://raw.githubusercontent.com/guardian/alerta/master/etc/httpd-alerta.conf
# FIXME - points to wsgi file in /opt/alerta...
# FIXME - wsgi file tries to activate virtualenv
a2ensite alerta

#cp /vagrant/files/alerta-dashboard.wsgi /var/www/alerta/alerta-dashboard.wsgi
#cp /vagrant/files/httpd-alerta-dashboard.conf /etc/apache2/sites-available/alerta-dashboard
#PYTHON_ROOT_DIR=`python -c "import alerta; print(alerta.__dict__['__path__'][0])"`
#sed -i "s#@STATIC@#$PYTHON_ROOT_DIR#" /etc/apache2/sites-available/alerta-dashboard
#a2ensite alerta-dashboard

a2dissite 000-default
echo "ServerName localhost" >> /etc/apache2/apache2.conf
apachectl restart

# Generate test alerts
wget -qO - /var/tmp/create-alerts.sh https://raw.githubusercontent.com/guardian/alerta/master/contrib/examples/create-new-alert.sh | sh

# Clean-up
mongo monitoring --eval 'db.heartbeats.remove()'
{'fraction_non_alphanumeric': 0.11763022323983972, 'fraction_numerical': 0.010875787063537493, 'mean_word_length': 4.7864238410596025, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 5, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1630860', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1232, 'n_words': 263}