Installing Cgit on CentOS 7

Get all the packages installed:

sudo yum install git-all httpd perl-Time-HiRes cgit composer highlight httpd-tools mariadb mariadb-server mod_ssl openssl pandoc patch php php-gd php-intl php-mysql php-tidy php-xcache php-xml python-markdown python-pygments

Set up the git user:

sudo /usr/sbin/groupadd git

sudo /usr/sbin/useradd -c "git user account" -d /srv/git -m -g git -s /bin/bash git

sudo passwd git

sudo usermod -aG git apache

sudo usermod -aG apache git

sudo usermod -aG git git

Give http a swift restart:

sudo systemctl restart httpd

Edit the cgit repo file to use cgit repos

sudo vi /etc/cgitrc

##and included like this:

include=/etc/cgitrepos

##

Create our first repo

sudo vi /etc/cgitrepos

section=Erik’s Really Cool Stuff

repo.url=erik.git

repo.path=/srv/git/erik.git

repo.desc=Erik repository

repo.owner=erik@Fuck.com

repo.readme=info/about.html

 

make the repo and set the permissions:

sudo mkdir /srv/git/erik.git/

sudo git init --bare /srv/git/erik.git

sudo chmod -R 2775 /srv/git/

sudo chown -R erik.git /srv/git/

Test it

http://yourserver.com/cgit 

git config –global user.name “Erik”

git config –global user.email

git init

git remote add origin 192.168.1.1:/srv/git/erik.git

git add .

git commit -m “Initial commit”

git push -u origin master

 

Troubleshooting:

sudo systemctl stop httpd

sudo rm -f /var/cache/cgit/*

sudo systemctl start httpd
Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Git

Client (make sure git is installed)

mkdir git

cd git

git config --global user.name "Erik" 

git config --global user.email your@email.net

ssh-copy-id 123.123.123.123

git clone ansible:/srv/git/erik.git

cd git/erik

ls

PUSH CHANGES

git add * 

git status

git commit -m "Comment" 

git push origin master

PULL CHANGES

cd into directory

git pull localhost:/srv/git/roles.git

###Disk Info

##Adding Disk Space

sudo pvcreate /dev/sdc
sudo vgextend centos_katello /dev/sdc
sudo lvextend -L 49G /dev/centos_katello/var_lib_mongodb
sudo lvresize -r /dev/centos_katello/var_lib_mongodb -L 49G

#fstab example

echo "###############################################################"
echo "# Add this to /etc/fstab: #"
echo "# #NFS Shares #"
echo "# 172.16.4.20:/Backup /home/erik nfs auto 0 0 #"
echo "# 172.16.4.20:/share /mnt/share nfs auto 0 0 #"
echo "###############################################################"

###Notes:

exec ssh-agent bash

ssh-add 

ssh 123.123.123.123
Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Speed Test RRD Setup

#First we need to install speedtest-cli.

#For Ubuntu and Raspberry Pi:

sudo apt-get install python-pip
pip install speedtest-cli
sudo pip install speedtest-cli

#For CentOS and the Like:

http://www.cyberciti.biz/faq/install-speedtest-cli-on-centos-redhat-fedoa-scientific-to-measure-internetspeed/

#Make Sure you have rrdtool installed:

sudo yum install rrdtool

##Create Graphs

mkdir /etc/speedtest
cd /etc/speedtest

##Then RRDTOOL magic:

sudo rrdtool create speedtest_dl.rrd -s 1800 DS:temp:GAUGE:3600:0:125 RRA:AVERAGE:0.5:1:576 RRA:AVERAGE:0.5:6:672 RRA:AVERAGE:0.5:24:732 RRA:AVERAGE:0.5:144:1460

sudo rrdtool create speedtest_ms.rrd -s 1800 DS:temp:GAUGE:3600:0:1000 RRA:AVERAGE:0.5:1:576 RRA:AVERAGE:0.5:6:672 RRA:AVERAGE:0.5:24:732 RRA:AVERAGE:0.5:144:1460

sudo rrdtool create speedtest_up.rrd -s 1800 DS:temp:GAUGE:3600:0:125 RRA:AVERAGE:0.5:1:576 RRA:AVERAGE:0.5:6:672 RRA:AVERAGE:0.5:24:732 RRA:AVERAGE:0.5:144:1460

##Then Create a script to run speedtest-cli, clean it up and stuff it into RRD

vi /usr/local/bin/speedtest-rrd

#! /bin/sh

#get into /tmp
cd /tmp

# get the EPOCH date
DATE=$(/bin/date +%s)

#Get the raw data
/usr/local/bin/speedtest-cli --simple > /tmp/speedtest-rrd.txt

#Clean it up and get raw Ping time in ms
RAW_MS=$(cat /tmp/speedtest-rrd.txt | grep P | sed -r 's/\s+//g'| cut -d":" -f2 | cut -d"m" -f1)

#Clean it up and get raw Download time in MiB
RAW_DL=$(cat /tmp/speedtest-rrd.txt | grep D | sed -r 's/\s+//g'| cut -d":" -f2 | cut -d"M" -f1)

#Clean it up and get raw Upload time in MiB
RAW_UP=$(cat /tmp/speedtest-rrd.txt | grep U | sed -r 's/\s+//g'| cut -d":" -f2 | cut -d"M" -f1)

#get data into rrd
cd /etc/speedtest/
rrdtool update speedtest_ms.rrd $DATE:$RAW_MS
rrdtool update speedtest_dl.rrd $DATE:$RAW_DL
rrdtool update speedtest_up.rrd $DATE:$RAW_UP

#create the daily graphs
#Ping Time
rrdtool graph /var/www/html/speedtest/speedtest_ms_day.png -s -1day DEF:speedtest_ms=speedtest_ms.rrd:temp:AVERAGE LINE1:speedtest_ms#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Download Speed
rrdtool graph /var/www/html/speedtest/speedtest_dl_day.png -s -1day DEF:speedtest_dl=speedtest_dl.rrd:temp:AVERAGE LINE1:speedtest_dl#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Upload Speed
rrdtool graph /var/www/html/speedtest/speedtest_up_day.png -s -1day DEF:speedtest_up=speedtest_up.rrd:temp:AVERAGE LINE1:speedtest_up#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#create the weekly graphs
#Ping Time
rrdtool graph /var/www/html/speedtest/speedtest_ms_week.png -s -1week DEF:speedtest_ms=speedtest_ms.rrd:temp:AVERAGE LINE1:speedtest_ms#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Download Speed
rrdtool graph /var/www/html/speedtest/speedtest_dl_week.png -s -1week DEF:speedtest_dl=speedtest_dl.rrd:temp:AVERAGE LINE1:speedtest_dl#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Upload Speed
rrdtool graph /var/www/html/speedtest/speedtest_up_week.png -s -1week DEF:speedtest_up=speedtest_up.rrd:temp:AVERAGE LINE1:speedtest_up#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#create the monthly graphs
#Ping Time
rrdtool graph /var/www/html/speedtest/speedtest_ms_month.png -s -1month DEF:speedtest_ms=speedtest_ms.rrd:temp:AVERAGE LINE1:speedtest_ms#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Download Speed
rrdtool graph /var/www/html/speedtest/speedtest_dl_month.png -s -1month DEF:speedtest_dl=speedtest_dl.rrd:temp:AVERAGE LINE1:speedtest_dl#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Upload Speed
rrdtool graph /var/www/html/speedtest/speedtest_up_month.png -s -1month DEF:speedtest_up=speedtest_up.rrd:temp:AVERAGE LINE1:speedtest_up#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#create the yearly graphs
#Ping Time
rrdtool graph /var/www/html/speedtest/speedtest_ms_year.png -s -1year DEF:speedtest_ms=speedtest_ms.rrd:temp:AVERAGE LINE1:speedtest_ms#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Download Speed
rrdtool graph /var/www/html/speedtest/speedtest_dl_year.png -s -1year DEF:speedtest_dl=speedtest_dl.rrd:temp:AVERAGE LINE1:speedtest_dl#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Upload Speed
rrdtool graph /var/www/html/speedtest/speedtest_up_year.png -s -1year DEF:speedtest_up=speedtest_up.rrd:temp:AVERAGE LINE1:speedtest_up#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#Clean up
rm /tmp/speedtest-rrd.txt

 

##Add to Cron

sudo crontab -e

#Add this to the bottom to run every 30 Minutes

*/30 * * * * /usr/local/bin/speedtest-rrd > /dev/null 2>&1

#

Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Installing LAMP

##Install Required Packages:

sudo yum install httpd mariadb-server mariadb php php-mysql mod_ssl openssl

##Start Up HTTP

sudo systemctl start httpd.service

##Setup the firewall

sudo firewall-cmd --permanent --zone=public --add-service=http 
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

##Test

https://web1.hohenfels.com

##Set to start on boot

sudo systemctl enable httpd.service

##Start MariaDB

sudo systemctl start mariadb

##Secure it

sudo mysql_secure_installation

##Enable to start on boot

sudo systemctl enable mariadb.service

##Test PHP

sudo vi /var/www/html/test.php
Add:
<?php phpinfo(); ?>

## Visit https://web1.hohenfels.com/test.php

Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Observium on CentOS 7

##Install the required packages

sudo yum install wget.x86_64 httpd.x86_64 php.x86_64 php-mysql.x86_64 php-gd.x86_64 php-posix php-mcrypt.x86_64 php-pear.noarch net-snmp.x86_64 net-snmp-utils.x86_64 fping.x86_64 mariadb-server.x86_64 mariadb.x86_64 MySQL-python.x86_64 rrdtool.x86_64 subversion.x86_64 jwhois.x86_64 ipmitool.x86_64 graphviz.x86_64 ImageMagick.x86_64 libvirt mod_ssl openssl

##Make the required directory and go to it

sudo mkdir -p /opt/observium && cd /opt

##Lets get the install package

sudo wget http://www.observium.org/observium-community-latest.tar.gz

##Un-tar it

sudo tar zxvf observium-community-latest.tar.gz

##Setup Maria if a new install

sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo /usr/bin/mysql_secure_installation

##Get into observium

cd observium

##Copy the default configuration file and edit it for your system.

sudo cp config.php.default config.php

##edit config.php and add DB user and password you will be creating below

sudo vi config.php

$config['db_user'] = 'observium';
$config['db_pass'] = 'password';

##While you are in there add:

$config['fping'] = "/usr/sbin/fping";

##Create the Database

mysql -u root -p
<mysql root password>
mysql> CREATE DATABASE observium DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
mysql> GRANT ALL PRIVILEGES ON observium.* TO 'observium'@'localhost'
 -> IDENTIFIED BY '<observium db password>';

##Setup the MySQL database and insert the default schema

sudo php includes/update/update.php

##Create the directory Observium will store its logs in:

sudo mkdir logs
sudo chown apache:apache logs

##Create the rrd directory to store RRDs in:

sudo mkdir rrd
sudo chown apache:apache rrd

##vi /etc/httpd/conf.d/observium.conf:

Alias /observium "/opt/observium/html/"
DocumentRoot "/opt/observium/html/"

<Directory "/opt/observium/html/">
 Options +FollowSymLinks
 AllowOverride All
 order allow,deny
 allow from all
 Require all granted
</Directory>

##Add a first user, use level of 10 for admin:

cd /opt/observium
sudo ./adduser.php <username> <password> <level>

sudo ./adduser.php admin password 10

##On Client

CentOS7

sudo yum install net-snmp

Ubuntu Variants

sudo apt-get install snmpd

##edit /etc/snmp/snmpd.conf

sudo vi /etc/snmp/snmpd.conf

###############################################################################
#
# snmpd.conf:
# Hohenfels/KJETT SNMP Configuration.
#
###############################################################################
agentaddress udp:161
# sec.name source community
 
com2sec Hohenfels_Network 192.168.1.0/24 LAN
com2sec Hohenfels_Network 172.16.4.0/24 DMZ
com2sec local localhost Local
 
# groupName securityModel securityName
group ReadOnlyGroup v2c Hohenfels_Network
group ReadOnlyGroup v2c local
 
 
# Make at least snmpwalk -v 1 localhost -c public system fast again.
# name incl/excl subtree mask(optional)
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
view systemview included .1
 
# group context sec.model sec.level prefix read write notif
access ReadOnlyGroup "" any noauth exact systemview none none
 
# System information
syslocation 78621
syscontact erik@mail.hohenfels.com

#This line allows Observium to detect the host OS if the distro script is installed
extend .1.3.6.1.4.1.2021.7890.1 distro /usr/bin/distro

##Restart the service

Ubuntu:

sudo service snmpd restart

CentOS:

sudo firewall-cmd --zone=public --add-port=161/udp --permanent
sudo systemctl restart firewalld.service
sudo systemctl enable snmpd
sudo systemctl start snmpd

##Add a first device to monitor

sudo ./add_device.php <hostname> <community> v2c

sudo ./add_device.php server DMZ v2c

##Do an initial discovery and polling run to populate the data for the new device

sudo ./discovery.php -h all
sudo ./poller.php -h all

##Add discovery and poller to cron

sudo vi /etc/cron.d/observium

33 */6 * * * root /opt/observium/discovery.php -h all >> /dev/null 2>&1
*/5 * * * * root /opt/observium/discovery.php -h new >> /dev/null 2>&1
*/5 * * * * root /opt/observium/poller-wrapper.py 2 >> /dev/null 2>&1

##Restart cron

sudo systemctl restart crond

##Logon using the username and password you set above.

http://server.tld/observium/

#

Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Raspberry Pi

The first thing I wanted to do was create a VPN Router/travel firewall. Most of the basic setup  is from here: http://makezine.com/projects/browse-anonymously-with-a-diy-raspberry-pi-vpntor-router/ 

The standard wireless drivers did not work with the Edimax EW-7811Un adapters I have. So I used these instructions to setup hostapd: http://www.daveconroy.com/turn-your-raspberry-pi-into-a-wifi-hotspot-with-edimax-nano-usb-ew-7811un-rtl8188cus-chipset/

I did not setup the bridged portion, I merged the above articles together.

After getting everything installed the way you want it make sure you back it up. I like to make a complete ‘dd’ copy of my SD card. Do a df to find out what your SD card is mounted as and then umount it. Then:

sudo dd bs=4M if=/dev/sdb of=raspbian.img

I then zip up the new image. I got a 30+ GB image to a 1.2GB zip file.

To restore:

sudo dd bs=4M if=raspbian.img of=/dev/sdb

##To get to the Raspberry Pi TUI:

sudo raspi-config

####New PI Install####

##Initial Setup

sudo raspi-config

Setup:

Expand Filesystem

Local Settings -> MAKE SURE TO CHANGE THE KEYBOARD TO US!!

##Add Erik

sudo useradd -m -d /home/erik erik

##Add erik to /etc/sudoers

erik    ALL=(ALL:ALL) ALL

##Set erik password

sudo passwd erik

##On fixer Laptop:

ssh-copy-id 192.168.1.8
scp .bashrc 192.168.1.8:/home/erik
scp .profile 192.168.1.8:/home/erik
scp .vimrc 192.168.1.8:/home/erik
scp bin/morning.sh 192.168.1.8:/home/erik
ssh 192.168.1.8

## Update the pi

mkdir /home/erik/bin
mv morning.sh /home/erik/bin
chmod 750 /bin/morning.sh
sudo /bin/morning.sh
sudo apt install vim vim-common rkhunter

## Get the rest of the stuff I need

mkdir /home/erik/Downloads
cd /home/erik/Downloads
wget http://web1.hohenfels.com/pub/pi/issue

## Setup SSH Banner

sudo mv issue /etc/
sudo rm /etc/issue.net
sudo ln -s /etc/issue /etc/issue.net
sudo vi /etc/ssh/sshd_config
#Banner /etc/issue.net
sudo service ssh restart

##Move the rest where it needs to go

mv /home/erik/Downloads/*.sh /home/erik/bin/
mv /home/erik/Downloads/wpa_supplicant_*.conf /home/erik/bin/

##Reboot

sudo reboot

##Power off and backup

 

 ###LAMP on Pi###

 

##Get the required packages:

sudo apt install apache2 php libapache2-mod-php mariadb-server mariadb-client php-mysql phpmyadmin

##Create a test PHP page to test php

sudo vi /var/www/html/testphp.php

And enter:

<?php phpinfo(); ?>

##Restart everything:

sudo service apache2 restart

sudo service mysql restart

##Go check our work

http://pi.hohenfels.com/testphp.php

http://pi.hohenfels.com/phpmyadmin

Secure the DB

mysql_secure_installation

 

##Other##

 

Wireless at the command line: wicd-curses

##

Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

The Energy Detective (TED) Data Gathering

Now that I am getting data and graphing it from the Enphase Envoy, I want to get data from my The Energy Detective (TED). I can then graphically view usage and compare it to my solar generation. Here is what I did:

 

I am setting this up on a CentOS 7 VM. I am already running Apache on it, I am not going to go over how to get that going. It is the same VM I used for the Enphase.

 

ted6000 is the name of my TED. You will see it a couple times in the script. Replace it with your URL

 

# If needed Install rrdtool and lynx (you will need the EPEL repos)

 

sudo yum install rrdtool lynx

 

# Then we create the database. I called mine ted.rrd, you can name your what you want. You will just need to note the name in the script below.

 

sudo rrdtool create ted.rrd -s 300 DS:temp:GAUGE:900:-55:125 RRA:AVERAGE:0.5:1:576 RRA:AVERAGE:0.5:6:672 RRA:AVERAGE:0.5:24:732 RRA:AVERAGE:0.5:144:1460

 

#Now create the web directory.

 

sudo mkdir /var/www/html/ted/

 

#I created the below script in /usr/local/bin/ and made it executable.

 

#!/bin/bash

# get the EPOCH date

 

DATE=$(/bin/date +%s)

#lets get in the right directory

 

cd /etc/ted/watts

#Now we get the data we need and get it into a number

 

RAW=$(lynx -dump http://ted6000/stats.htm | grep '(W)' | sed -r 's/\s+//g'| cut -d":" -f2)

#make it a variable

 

KW=$(/usr/bin/echo "scale=3; $RAW/1000" | bc -l)

#get data into rrd

 

rrdtool update ted_watts.rrd $DATE:$KW

#create daily graph

 

rrdtool graph /var/www/html/ted/ted_watts_day.png -s -1day DEF:ted_watts=ted_watts.rrd:temp:AVERAGE LINE1:ted_watts#FF9900 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#create weekly graph

 

rrdtool graph /var/www/html/ted/ted_watts_week.png -s -1week DEF:ted_watts=ted_watts.rrd:temp:AVERAGE LINE1:ted_watts#FF9900 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#create monthly graph

 

rrdtool graph /var/www/html/ted/ted_watts_month.png -s -1month DEF:ted_watts=ted_watts.rrd:temp:AVERAGE LINE1:ted_watts#FF9900 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

#create yearly graph

 

rrdtool graph /var/www/html/ted/ted_watts_year.png -s -1year DEF:ted_watts=ted_watts.rrd:temp:AVERAGE LINE1:ted_watts#FF9900 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

 

 

##Here is the final Product:

 

Daily

 

ted watts day

 

Weekly:

 

ted watts week

 

Month:

 

ted watts month

##Here it the no mark-up version:

 

#!/bin/bash

# get the EPOCH date
DATE=$(/bin/date +%s)

#lets get in the right directory
cd /etc/ted/watts

#Now we get the data we need and get it into a number
RAW=$(lynx -dump http://ted6000/stats.htm | grep ‘(W)’ | sed -r ‘s/\s+//g’| cut -d”:” -f2)

#make it Kw and put it in a file I can use for other things
#/usr/bin/echo “scale=3; $RAW/1000” | bc -l |sed ‘s/^/, /’ | sed -e “s/^/$(date) /” >> TED_DATA.csv

#make it a variable
KW=$(/usr/bin/echo “scale=3; $RAW/1000” | bc -l)

#get data into rrd
rrdtool update ted_watts.rrd $DATE:$KW

#create daily graph
rrdtool graph /var/www/html/ted/ted_watts_day.png -s -1day DEF:ted_watts=ted_watts.rrd:temp:AVERAGE LINE1:ted_watts#FF9900 -h 400 -w 600 -y1:2 –color GRID#dddddd –color MGRID#aaaaaa

#create weekly graph
rrdtool graph /var/www/html/ted/ted_watts_week.png -s -1week DEF:ted_watts=ted_watts.rrd:temp:AVERAGE LINE1:ted_watts#FF9900 -h 400 -w 600 -y1:2 –color GRID#dddddd –color MGRID#aaaaaa

#create monthly graph
rrdtool graph /var/www/html/ted/ted_watts_month.png -s -1month DEF:ted_watts=ted_watts.rrd:temp:AVERAGE LINE1:ted_watts#FF9900 -h 400 -w 600 -y1:2 –color GRID#dddddd –color MGRID#aaaaaa

#create yearly graph
rrdtool graph /var/www/html/ted/ted_watts_year.png -s -1year DEF:ted_watts=ted_watts.rrd:temp:AVERAGE LINE1:ted_watts#FF9900 -h 400 -w 600 -y1:2 –color GRID#dddddd –color MGRID#aaaaaa

Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather

Enphase Data Gathering

I wanted to see if I could pull data from my Enphase and stuff it in a graph for my own use. Turns out using the power of open source anything can be done. This is what I did:

I am setting this up on a CentOS 7 VM. I am already running Apache on it, I am not going to go over how to get that going.

Solar is the name of my Enphase Envoy. You will see it a couple times in the script. Replace it with your URL

# Install rrdtool and lynx (you will need the EPEL repos)

sudo yum install rrdtool lynx

 

#Then we create the database. I called mine enphase.rrd, you can name your what you want. You will just need to note the name in the script below.

sudo rrdtool create enphase.rrd -s 300 DS:temp:GAUGE:900:-55:125 RRA:AVERAGE:0.5:1:576 RRA:AVERAGE:0.5:6:672 RRA:AVERAGE:0.5:24:732 RRA:AVERAGE:0.5:144:1460

 

#Now create the web directory.

sudo mkdir /var/www/html/enphase/

 

#I created the below script in /usr/local/bin/ and made it executable.

#!/bin/bash
# get the EPOCH date

DATE=$(/bin/date +%s)

 

# get to the right directory

cd /etc/enphase

 

# remove old files

rm ENPHASE.csv
rm kw2.txt

 

# Get the data and dump it into a CSV file

lynx -dump http://solar.hohenfels.com/production?locale=en | grep ly > kw.txt

 

# The Enphase Envoy uses Kilowatts (kW) and Watts (W). So a little creativity is required: If I find kW, clean it up, add the date and dump it in the CSV. If I dont find kW then clean it up and put it in a text file called kw2.txt. If it is not kW then it has to be W. when not producing it shows 0W

if grep -q 'kW' "kw.txt"; then
cat kw.txt | sed 's/[A-Za-z%]*//g' | sed -r 's/\s+//g' | sed 's/^/, /' | sed -e "s/^/$(date) /" >> ENPHASE.csv
else
cat kw.txt | sed 's/[A-Za-z%]*//g' | sed -r 's/\s+//g' > kw2.txt
fi

 

# Make the kw2.txt file a variable

 KW2=$(cat kw2.txt)

# Do some math and get our variable into kW and dump it in the CSV.

/usr/bin/echo "scale=3; $KW2/1000" | bc -l |sed 's/^/, /' | sed -e "s/^/$(date) /" >> ENPHASE.csv

 

# Get the data into a variable we can use for RRD

KW=$(cat ENPHASE.csv | sed 's/[A-Za-z ]*//g' | cut -d"," -f2)

# I wanted to make sure things worked up to this point:

echo $KW >> debug.log
echo $DATE >> debug.log

# Finally get data into rrd

rrdtool update enphase.rrd $DATE:$KW

# create daily graph

rrdtool graph /var/www/html/enphase/enphase_day.png -s -1day DEF:enphase=enphase.rrd:temp:AVERAGE LINE1:enphase#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa 

 

# create weekly graph

rrdtool graph /var/www/html/enphase/enphase_week.png -s -1week DEF:enphase=enphase.rrd:temp:AVERAGE LINE1:enphase#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

# create monthly graph

rrdtool graph /var/www/html/enphase/enphase_month.png -s -1month DEF:enphase=enphase.rrd:temp:AVERAGE LINE1:enphase#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

# create yearly graph

rrdtool graph /var/www/html/enphase/enphase_year.png -s -1year DEF:enphase=enphase.rrd:temp:AVERAGE LINE1:enphase#00CC00 -h 400 -w 600 -y1:2 --color GRID#dddddd --color MGRID#aaaaaa

 

##Here is the final daily product:

enphase day

##Weekly

 

enphase week

 

#Month

 

enphase month

 

# Here it is with no mark-up:

#!/bin/bash

# get the EPOCH date

DATE=$(/bin/date +%s)

#get to the right directory

cd /etc/enphase

#remove old files

rm ENPHASE.csv
rm kw2.txt

#Get the data ready for a csv for MariaDB

lynx -dump http://solar.hohenfels.com/production?locale=en | grep ly > kw.txt

if grep -q ‘kW’ “kw.txt”; then
cat kw.txt | sed ‘s/[A-Za-z%]*//g’ | sed -r ‘s/\s+//g’ | sed ‘s/^/, /’ | sed -e “s/^/$(date) /” >> ENPHASE.csv
else
cat kw.txt | sed ‘s/[A-Za-z%]*//g’ | sed -r ‘s/\s+//g’ > kw2.txt
fi

KW2=$(cat kw2.txt)

/usr/bin/echo “scale=3; $KW2/1000” | bc -l |sed ‘s/^/, /’ | sed -e “s/^/$(date) /” >> ENPHASE.csv

#Get the data into a variable

KW=$(cat ENPHASE.csv | sed ‘s/[A-Za-z ]*//g’ | cut -d”,” -f2)

##DEBUG

echo $KW >> debug.log
echo $DATE >> debug.log

#get data into rrd

rrdtool update enphase.rrd $DATE:$KW

#create daily graph

rrdtool graph /var/www/html/enphase/enphase_day.png -s -1day DEF:enphase=enphase.rrd:temp:AVERAGE LINE1:enphase#00CC00 -h 400 -w 600 -y1:2 –color GRID#dddddd –color MGRID#aaaaaa

#create weekly graph

rrdtool graph /var/www/html/enphase/enphase_week.png -s -1week DEF:enphase=enphase.rrd:temp:AVERAGE LINE1:enphase#00CC00 -h 400 -w 600 -y1:2 –color GRID#dddddd –color MGRID#aaaaaa

#create monthly graph

rrdtool graph /var/www/html/enphase/enphase_month.png -s -1month DEF:enphase=enphase.rrd:temp:AVERAGE LINE1:enphase#00CC00 -h 400 -w 600 -y1:2 –color GRID#dddddd –color MGRID#aaaaaa

#create yearly graph

rrdtool graph /var/www/html/enphase/enphase_year.png -s -1year DEF:enphase=enphase.rrd:temp:AVERAGE LINE1:enphase#00CC00 -h 400 -w 600 -y1:2 –color GRID#dddddd –color MGRID#aaaaaa

Facebooktwittergoogle_plusredditpinterestlinkedinmailby feather