Skip to content

Instantly share code, notes, and snippets.

@deepak7093
Last active July 29, 2019 17:01
Show Gist options
  • Save deepak7093/3476a3c1ba5c4f227a92a87f740217bb to your computer and use it in GitHub Desktop.
Save deepak7093/3476a3c1ba5c4f227a92a87f740217bb to your computer and use it in GitHub Desktop.
Netdata host file intergrity checker plugin

Netdata host file integrity check with statsd

  1. Check statsd plugin status Statsd is enabled by default, if not enable it inside, /etc/netdata/netdata.conf under [statsd] section. Default port is 8125.

  2. Create config file /etc/netdata/statsd.d/file.conf with below content Run # mkdir -p /etc/netdata/statsd.d/

Run # vi /etc/netdata/statsd.d/file.conf

[app]
  name = filecheckapp
  metrics = hosts resolve
  private charts = yes

[file_chart1]
  title = Files Integrity Check
  family = file_family
  context = filecheckapp.filecheck
  units = filecheck
  type = area
  dimension = hosts 'hosts me' last 1 1
  dimension = resolve 'resolve me' last 1 1
  1. Create dir to store user scripts

Run # mkdir -p /etc/netdata/scripts/

  1. Run # vi /etc/netdata/scripts/etc_host_check.sh

Add content

#!/bin/bash
rm original_host
wget <GIT_URL> -O original_host
base_md5=`md5sum original_host  | cut -d' ' -f1`
server_md5=`md5sum /etc/hosts | cut -d' ' -f1`
flag=`cat /etc/netdata/scripts/flag.txt`

if [[ $base_md5 == $server_md5 ]] && [[ $flag == 0 ]];
	then
		echo "No change Required"

elif [[ $base_md5 == $server_md5 ]] && [[ $flag == 1 ]];
	then
		echo "OK : Host has valid /etc/hosts conf !!!"
		echo 0 > /etc/netdata/scripts/flag.txt; echo "hosts:-1|g" | nc -w 1 -u localhost 8125;
elif [[ $base_md5 != $server_md5 ]] && [[ $flag == 0 ]];
	then
	echo 1 > /etc/netdata/scripts/flag.txt;
	echo "WARNING: /etc/hosts file got changed."
	echo "hosts:+1|g" | nc -w 1 -u localhost 8125;
else
	echo "Do nothig.."
  1. Change localhost to your netdata server ip in above script.
  2. Change <GIT_URL> to your original conf file.
  3. Run # mkdir -p /etc/netdata/scripts/

Run # touch /etc/netdata/scripts/flag.txt

Run # echo 0 > /etc/netdata/scripts/flag.txt

  1. Now set cronjob to run script every 1 min

Run # crontab -e

Add * * * * * run-parts /etc/netdata/scripts/etc_host_check.sh

  1. Now you must be able to gauge metrics under netdata statsd.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment