From b4910dac500da6ff7ec671e0e213474455eb1d4b Mon Sep 17 00:00:00 2001 From: Christian Pape Date: Tue, 12 Jun 2018 19:35:03 -0500 Subject: [PATCH] first commit --- .gitignore | 4 +++ gns3-qemu.json | 43 +++++++++++++++++++++++++ gns3-vmware.json | 47 +++++++++++++++++++++++++++ http/ks.cfg | 36 +++++++++++++++++++++ scripts/base.sh | 3 ++ scripts/cleanup.sh | 3 ++ scripts/grafana.sh | 8 +++++ scripts/opennms.sh | 77 +++++++++++++++++++++++++++++++++++++++++++++ scripts/vmware.sh | 1 + scripts/zerodisk.sh | 3 ++ 10 files changed, 225 insertions(+) create mode 100644 .gitignore create mode 100644 gns3-qemu.json create mode 100644 gns3-vmware.json create mode 100644 http/ks.cfg create mode 100644 scripts/base.sh create mode 100644 scripts/cleanup.sh create mode 100644 scripts/grafana.sh create mode 100644 scripts/opennms.sh create mode 100644 scripts/vmware.sh create mode 100644 scripts/zerodisk.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2584887 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +output-vmware-iso +output-qemu +packer_cache +.DS_Store diff --git a/gns3-qemu.json b/gns3-qemu.json new file mode 100644 index 0000000..d68ed77 --- /dev/null +++ b/gns3-qemu.json @@ -0,0 +1,43 @@ +{ + "variables": { + "iso_mirror": "mirror.informatik.hs-fulda.de", + "opennms_release": "stable", + "onms-version": "22.0.0-1" + }, + "builders": [ + { + "type": "qemu", + "accelerator": "kvm", + "boot_command": [ + " text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" + ], + "boot_wait": "10s", + "disk_size": 20000, + "headless": true, + "http_directory": "http", + "iso_checksum": "714acc0aefb32b7d51b515e25546835e55a90da9fb00417fbee2d03a62801efd", + "iso_checksum_type": "sha256", + "iso_url": "https://{{user `iso_mirror`}}/centos/7.5.1804/isos/x86_64/CentOS-7-x86_64-Minimal-1804.iso", + "ssh_username": "root", + "ssh_password": "secret", + "ssh_port": 22, + "ssh_wait_timeout": "10000s", + "shutdown_command": "/sbin/halt -h -p" + } + ], + "provisioners": [ + { + "type": "shell", + "override": { + "vmware-iso": { + "scripts": [ + "scripts/base.sh", + "scripts/opennms.sh", + "scripts/grafana.sh", + "scripts/cleanup.sh" + ] + } + } + } + ] +} diff --git a/gns3-vmware.json b/gns3-vmware.json new file mode 100644 index 0000000..8c23659 --- /dev/null +++ b/gns3-vmware.json @@ -0,0 +1,47 @@ +{ + "variables": { + "iso_mirror": "mirror.informatik.hs-fulda.de", + "opennms_release": "stable", + "onms-version": "22.0.0-1" + }, + "builders": [ + { + "type": "vmware-iso", + "boot_command": [ + " text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg" + ], + "boot_wait": "10s", + "disk_size": 20000, + "headless": true, + "http_directory": "http", + "iso_checksum": "714acc0aefb32b7d51b515e25546835e55a90da9fb00417fbee2d03a62801efd", + "iso_checksum_type": "sha256", + "iso_url": "https://{{user `iso_mirror`}}/centos/7.5.1804/isos/x86_64/CentOS-7-x86_64-Minimal-1804.iso", + "ssh_username": "root", + "ssh_password": "secret", + "ssh_port": 22, + "ssh_wait_timeout": "10000s", + "shutdown_command": "/sbin/halt -h -p", + "vmx_data_post": { + "memsize": "8192", + "numvcpus": "2" + } + } + ], + "provisioners": [ + { + "type": "shell", + "override": { + "vmware-iso": { + "scripts": [ + "scripts/base.sh", + "scripts/vmware.sh", + "scripts/opennms.sh", + "scripts/grafana.sh", + "scripts/cleanup.sh" + ] + } + } + } + ] +} diff --git a/http/ks.cfg b/http/ks.cfg new file mode 100644 index 0000000..719e85f --- /dev/null +++ b/http/ks.cfg @@ -0,0 +1,36 @@ +install +cdrom +lang en_US.UTF-8 +keyboard us +network --onboot yes --device eth0 --bootproto dhcp --noipv6 +rootpw --plaintext secret +firewall --enabled --service=ssh +authconfig --enableshadow --passalgo=sha512 +selinux --disabled +timezone Europe/Berlin +bootloader --location=mbr --driveorder=sda --append="crashkernel=auto rhgb quiet" + +text +skipx +zerombr + +clearpart --all --initlabel +autopart + +auth --useshadow --enablemd5 +firstboot --disabled +reboot + +%packages --ignoremissing +@core +bzip2 +kernel-devel +kernel-headers +-ipw2100-firmware +-ipw2200-firmware +-ivtv-firmware +%end + +%post +/usr/bin/yum -y install sudo +%end diff --git a/scripts/base.sh b/scripts/base.sh new file mode 100644 index 0000000..f3e482c --- /dev/null +++ b/scripts/base.sh @@ -0,0 +1,3 @@ +sed -i "s/^.*requiretty/#Defaults requiretty/" /etc/sudoers +yum -y install gcc make gcc-c++ kernel-devel-`uname -r` perl + diff --git a/scripts/cleanup.sh b/scripts/cleanup.sh new file mode 100644 index 0000000..dec8b62 --- /dev/null +++ b/scripts/cleanup.sh @@ -0,0 +1,3 @@ +yum -y clean all +rm -rf /tmp/rubygems-* + diff --git a/scripts/grafana.sh b/scripts/grafana.sh new file mode 100644 index 0000000..0b86af5 --- /dev/null +++ b/scripts/grafana.sh @@ -0,0 +1,8 @@ +yum install -y opennms-helm + +systemctl enable grafana-server +systemctl start grafana-server + +firewall-cmd --zone=public --permanent --add-port=3000/tcp +sleep 10 +curl 'http://admin:admin@localhost:3000/api/datasources' -X POST -H 'Content-Type:application/json;charset=UTF-8' --data-binary '{"name":"OpenNMS","type":"opennms","access":"proxy","url":"http://localhost:8980/opennms","isDefault":true,"basicAuth":true,"basicAuthUser":"admin","basicAuthPassword":"admin"}' diff --git a/scripts/opennms.sh b/scripts/opennms.sh new file mode 100644 index 0000000..b5e725f --- /dev/null +++ b/scripts/opennms.sh @@ -0,0 +1,77 @@ +# Install some tools +yum -y install net-tools wget htop iftop sysstat tcpdump vim git tar unzip psmisc + +# Additional packages +yum -y install net-snmp-utils net-snmp +yum -y install bind-utils mailx + +# Install OpenNMS repository +rpm -Uvh http://yum.opennms.org/repofiles/opennms-repo-stable-rhel7.noarch.rpm +rpm --import http://yum.opennms.org/OPENNMS-GPG-KEY + +# Install OpenNMS without any setup +yum -y install rrdtool +yum -y install opennms +yum -y install jrrd2 +yum clean all + +# Set Java +/opt/opennms/bin/runjava -s + +# Initialize PostgreSQL database +postgresql-setup initdb + +# Set authentication from ident to md5 +sed -i 's/all 127\.0\.0\.1\/32 ident/all 127.0.0.1\/32 md5/g' /var/lib/pgsql/data/pg_hba.conf +sed -i 's/all ::1\/128 ident/all ::1\/128 md5/g' /var/lib/pgsql/data/pg_hba.conf + +# Enable and start PostgreSQL with systemd +systemctl start postgresql +systemctl enable postgresql + +# Create opennms user with password and database +sudo -u postgres psql -c "CREATE USER opennms WITH PASSWORD 'opennms';" +sudo -u postgres psql -c "CREATE DATABASE opennms;" +sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE opennms to opennms;" + +# Create OpenNMS database configuration +printf ' + + + + + + +' opennms opennms opennms opennms \ + > /opt/opennms/etc/opennms-datasources.xml + +# Initialize OpenNMS database schema +/opt/opennms/bin/install -dis + +echo "org.opennms.rrd.storeByForeignSource=true" >> /opt/opennms/etc/opennms.properties + +# Configure OpenNMS to use RRDtool +echo "org.opennms.rrd.strategyClass=org.opennms.netmgt.rrd.rrdtool.MultithreadedJniRrdStrategy" >> /opt/opennms/etc/rrd-configuration.properties +echo "org.opennms.rrd.interfaceJar=/usr/share/java/jrrd2.jar" >> /opt/opennms/etc/rrd-configuration.properties +echo "opennms.library.jrrd2=/usr/lib64/libjrrd2.so" >> /opt/opennms/etc/rrd-configuration.properties + +# Enable and start OpenNMS with systemd +systemctl start opennms +systemctl enable opennms + +firewall-cmd --zone=public --permanent --add-port=8980/tcp diff --git a/scripts/vmware.sh b/scripts/vmware.sh new file mode 100644 index 0000000..1de6d1e --- /dev/null +++ b/scripts/vmware.sh @@ -0,0 +1 @@ +yum install -y fuse-libs open-vm-tools diff --git a/scripts/zerodisk.sh b/scripts/zerodisk.sh new file mode 100644 index 0000000..948fb29 --- /dev/null +++ b/scripts/zerodisk.sh @@ -0,0 +1,3 @@ +dd if=/dev/zero of=/EMPTY bs=1M +rm -f /EMPTY +sync