Goal : We have diff config notification if there are config changes on network devices
Requirements:
- msmtp
- msmtp-mta
- ansi2html
- oxidized script
Package Installation
pip install ansi2html
apt-get install colordiff msmtp msmtp-mta -y
Put the script below, it will automatically create oxidized-report-git-commits in folder /opt/oxidized
cat <<'EOF' > /opt/oxidized/oxidized-report-git-commits #!/bin/sh echo "Node name: ${OX_NODE_NAME}" echo "Group name: ${OX_NODE_GROUP}" echo "Job status: ${OX_JOB_STATUS}" echo "Job time: ${OX_JOB_TIME}" if [ "${OX_EVENT}" = "node_fail" ]; then echo 'Job failed' exit 64 fi if [ -z "${OX_REPO_COMMITREF}" ]; then echo '$OX_REPO_COMMITREF not set' exit 64 fi if [ -z "${OX_REPO_NAME}" ]; then echo '$OX_REPO_NAME not set' exit 64 fi echo "Git repo: ${OX_REPO_NAME}" echo "Git commit ID: ${OX_REPO_COMMITREF}" echo "" git --bare --git-dir="${OX_REPO_NAME}" show --pretty='' --no-color "${OX_REPO_COMMITREF}" EOF
chmod +x /opt/oxidized/oxidized-report-git-commits
cat <<EOF > /etc/msmtprc # Set default values for all following accounts. defaults auth on tls on tls_trust_file /etc/ssl/certs/ca-certificates.crt logfile ~/.msmtp.log # Gmail account gmail host smtp.gmail.com port 587 from geeksopslab@gmail.com user geeksopslab@gmail.com password HIDDENPASSWORD!! # Set a default account account default : gmail EOF
The part of configuration which will send via email if there are change configuration on network devices. Edit file in /opt/oxidized/.config/oxidized/config and put the configuration below
hooks: email_output: type: exec events: [post_store] cmd: 'echo "From:Oxidized\nTo:geeksopslab@gmail.com\nSubject: Production Network - Config diff ${OX_NODE_NAME}\nMIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n\n" > /tmp/${OX_NODE_NAME}; bash /opt/oxidized/oxidized-report-git-commits | tr -d \\r | colordiff | ansi2html >> /tmp/${OX_NODE_NAME}; msmtp rohmat.trie@gmail.com< /tmp/${OX_NODE_NAME}; rm /tmp/${OX_NODE_NAME}' async: true timeout: 120
Sample output