LibreNMS enable RRDCached on CentOS 7

Commands from https://docs.librenms.org/Extensions/RRDCached/

Create System Service

sudo vi /etc/systemd/system/rrdcached.service
[Unit]
Description=Data caching daemon for rrdtool
After=network.service
[Service]
Type=forking
PIDFile=/run/rrdcached.pid
ExecStart=/usr/bin/rrdcached -w 1800 -z 1800 -f 3600 -s librenms -U librenms -G librenms -B -R -j /var/tmp -l unix:/run/rrdcached.sock -t 4 -F -b /opt/librenms/rrd/
[Install]
WantedBy=default.target

Save with esc + :wq

Enable rrdcached service on boot up and start the service now

systemctl enable --now rrdcached.service

Enable RRDcached in librenms config

vi /opt/librenms/config.php

add/edit the following line. If it is commented out, uncomment it

$config['rrdcached'] = "unix:/run/rrdcached.sock";

Save with esc + :wq

Check the disk IO after a little bit to see if it went down.

VIM/SED Search and replace lines that do not contain numbers

Objective: Find all lines in a file that only contain alpha characters and delete or replace.

Sample contents of file.

 Z2j2NH23
VTQnPwSS
hFbxgvFt
VSVR8v3F
GPrP4zo

The following sed command works for our objective.

sed s/[[:alpha:]]\{8\}/ALPHAONLY/g file.txt

The part in the [] tells sed to search for any alpha characters a-Z, the part in bold \{8\} tells it to search 8 spaces out (Change if needed) and ALPHAONLY is what alpha line will get substituted to.

sed s/[[:alpha:]]\{8\}/ALPHAONLY/g



Returns

Z2j2NH23
ALPHAONLY
ALPHAONLY
VSVR8v3F
GPrP4zo9

You can run the same basic syntax in VI

Search and replace

:%s/[[:alpha:]]\{8\}/ALPHAONLY/g 

Or to delete the lines

:%d/[[:alpha:]]\{8\}/d

You can also change [[:alpha:]] for [[:digit:]] if you want to search for numbers instead.

Secure Erase Hard Drive using DD

The following commands are dangerous! Proceed with caution!

Change /dev/sdX to your drive. Make sure you get the correct drive, or you could wipe you main system.

dd if=/dev/zero of=/dev/sdX bs=1M status=progress

The status=progress part shows how much dd has writen. Helpful to gauge how far along it is.

If you want a more secure way to erase the drive, change zero to random. Makes it slower, but should be more secure.

dd if=/dev/random of=/dev/sdX bs=1M status=progres

Side note, these commands should work in macOS, but you may need to drop the status=progress option.

LibreNMS manually clean up MySQL Syslog Database

Adding the following option to the config.php file is supposed to delete anything over 30 days.

$config['syslog_purge']                                 = 30;

You can also manually delete the entries out of the MySQL database by logging into MySQL, selecting the librenms database, and running the command below.

The command deletes all entries older than 12/9/2018 at 08:00. Change the date and time as needed.

DELETE FROM syslog WHERE timestamp < '2018-12-9 08:00:00';

The following link has some more clean up options.
https://docs.librenms.org/Support/Cleanup-options/

BASH Script to add new SFTP user and setup permissions

This script adds a new SFTP user with only sftp access.  Refer to this post on setting up a SFTP server.

Download script

wget www.incredigeek.com/home/downloads/scripts/sftpUserAdd.sh

Make executable

chmod +x sftpUserAdd.sh

Run with the new user you want to create.

./sftpUserAdd.sh sftpUsername

You may need to edit the script and modify the location parameters.

#!/bin/bash
# Automatically setup and add SFTP user
# Script creates new user and setups permissions
newUser=$1
sftpDir="/sftp/"
if grep -q ${newUser} /etc/passwd ;then
echo ${newUser} Already exsists. Aborting!
exit 1
else
mkdir -p ${sftpDir}/${newUser}/files
useradd -g sftpusers -d ${sftpDir}/${newUser}/files -s /sbin/nologin ${newUser}
passwd ${newUser}
chown ${newUser}:sftpusers /sftp/CareMark/files
fi

Ubuntu apt-get install, error with org.freedesktop.systemd1.service

Had an issue trying to recover from a failed upgrade.  Apt would complain about dependencies, suggested running apt-get install -f.

Running apt-get install -f would still fail.  It showed a conflict with the systemd1.service, ended up renaming the file with the following command

sudo mv /usr/share/dbus-1/system-service/org.freedesktop.systemd1.service{,bak}

and reran

sudo apt-get install -f

after that I was able to rerun the upgrade and finish

sudo apt-get upgrade

Connect to WiFi network via command line

Easiest way is to use the Network Manager nmtui tool

nmtui

It gives you a “command line GUI” to search and select your preferred WiFi network.

Alternate way is to use the iw tools.

Scan for available WiFi networks

iwlist scan

Connect with iwconfig, replace WiFiName with your WiFi name.  Note this only works with open networks.

iwconfig wlan0 essid WiFiName

You’ll need to get an address now, so run

dhclient

Check if your DNS is working.  If not, as a “hack” manually add it to /etc/resolv.conf and restart the networking service.

sudo echo "nameserver 8.8.8.8" >> /etc/resolv.conf
sudo service networking restart

Your not supposed to manually put the nameservers in resolv.conf.  But it works in a pinch.