-numerous changes to work with Raspbian 10

-redo of some roles, particularly GUI
-modifications to support working from a "Raspbian Lite" install
This commit is contained in:
mpelle426
2019-07-10 14:24:34 +01:00
parent f86279f3cc
commit ed7eabd399
61 changed files with 12386 additions and 12383 deletions

View File

@@ -1,23 +1,23 @@
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAjqnbFpamk/ko2FvgfHLvTsegVJGJ6sjNmG0E/MgWEPU+QwLBMRMSk0vLeasn
21P4EDHnwqBUdUmZYitOzPAmVG6G97Q3g8X/O75Ju08z+ijk09n0gDgKDx/4Z/KeSqMSDLb1V77u
SOWgjV6Snbnivs2Vfd3HF4Apu2i/BqjOXBPoQxtF1xFSg8JOKjWQzfY5WXRiYssNTmCPTI/dFERR
nqGws8GXeVbRv8+Yl7sP0VIVJ/FpVLZul20keta/8ISiu9Y4TkgjKLn9P5P5V0ySdmG7INIUDSzc
VGxEUuumdoul6r2gDMDUhxvduZGy0sfzPvt49NI23tq13AsSpzhV1wIDAQABAoIBABrJxjvdmfXb
KVJHHkYABvOSBIcctPsDLafbgL4+i/YvNru6frBKVoiWCOUVwGwsvj28QTqIhJNpeIW4gBl3Vpsw
DePhUTNLMHv1ZT7oxmfI2f71xDV3UFw6sphCNHrrV+5PRI5vaasCgz1IbttzFiKh09pIlKPTCwMH
zibf96/OPDps3Tdoi6NNm0GOiApt56M/p/Rjg8zaMUrpkMfEWw4v6RAHRtOTW2u1guXRBehJvQMW
Sm15cjJ0/NI7rlA7rmkZnioytGDzd7hFa/7VBnOObcHy+/E3cFeK1Yn361oIbvR9Wy9T+CrciRDE
zcLawr3VBsAfd5n5wTuoel1vLyECgYEA5G2S6TZTFRLvn22hESbsw+9UGoqBvpO0dVTNi0PnhmHj
H7CA4FlD4cBqKdv51WBoaeM6zgI14e+LjXdOdvEnaMn0g3RDRPRF9LVwxq4kPKBuOHaSY3UF/czt
HzKCDBMc/L4rYgrYKYKPk8nY1qL2w7iqJsT1UMYBOI0et4bMLo8CgYEAn+Iod9UWjBQkIory6Q+3
06tLm9iMCgfPNrHCqKiwR4s7+1EMZi828oNu8piO2XjzNhbrf2jjfqL9GzYdTjM0ex/wSKOUpTZU
JkBjbnwJJVpdKV8NRBUbT+JsG9TzdPxhHlENkX7znu9QgL7hNOW03E0ICo9CoWro0R1LLMeaiDkC
gYAayvtrXVLbavAuTAaTY3Rr+vtrbYmQV/TXuk2toxZZ/ctNIT/MkMvUg+Qv6rxgGcHFgcCY/0tg
p98/hZnve5O6x81lSdLGGLzH2ixTMYPQlKS4/Ldo8QX14f6CJUN5tRg2UPv3sPvvyn+avxcu/chh
5pwWlg2MHt1vy6Wpsybp4wKBgFHXR5XHmuoLaU/RRnRsmlGcbnCREWYVB0ndBmKlLs8Ag6yqmSk5
Y+wRwVonI4BIvF5krxmiDEmHjv493hRoe6XG/I2CRpWnUL3f2cX1cg0Py35g7H58O2XR5jr8775j
bidBoCtpC7XAlLnCe69DIiheug4FtTrBafmZACEk74JpAoGANstOzkZ3NYws0z0pnvsV8I0/p8WU
AVCA0i+hMC7u3KWSeGxsJIEN4GlFHruFSV5rF8NbTdESnb7lNNPqppmakmcLtydsAgCZYfHJNJGp
hhI+4O3vf38aqkEruwsR83dzrZZi/ab2DEvuVHbVWGfQNrSV4Hq7te4Pk+MajpYaNeU=
-----END RSA PRIVATE KEY-----
-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAjqnbFpamk/ko2FvgfHLvTsegVJGJ6sjNmG0E/MgWEPU+QwLBMRMSk0vLeasn
21P4EDHnwqBUdUmZYitOzPAmVG6G97Q3g8X/O75Ju08z+ijk09n0gDgKDx/4Z/KeSqMSDLb1V77u
SOWgjV6Snbnivs2Vfd3HF4Apu2i/BqjOXBPoQxtF1xFSg8JOKjWQzfY5WXRiYssNTmCPTI/dFERR
nqGws8GXeVbRv8+Yl7sP0VIVJ/FpVLZul20keta/8ISiu9Y4TkgjKLn9P5P5V0ySdmG7INIUDSzc
VGxEUuumdoul6r2gDMDUhxvduZGy0sfzPvt49NI23tq13AsSpzhV1wIDAQABAoIBABrJxjvdmfXb
KVJHHkYABvOSBIcctPsDLafbgL4+i/YvNru6frBKVoiWCOUVwGwsvj28QTqIhJNpeIW4gBl3Vpsw
DePhUTNLMHv1ZT7oxmfI2f71xDV3UFw6sphCNHrrV+5PRI5vaasCgz1IbttzFiKh09pIlKPTCwMH
zibf96/OPDps3Tdoi6NNm0GOiApt56M/p/Rjg8zaMUrpkMfEWw4v6RAHRtOTW2u1guXRBehJvQMW
Sm15cjJ0/NI7rlA7rmkZnioytGDzd7hFa/7VBnOObcHy+/E3cFeK1Yn361oIbvR9Wy9T+CrciRDE
zcLawr3VBsAfd5n5wTuoel1vLyECgYEA5G2S6TZTFRLvn22hESbsw+9UGoqBvpO0dVTNi0PnhmHj
H7CA4FlD4cBqKdv51WBoaeM6zgI14e+LjXdOdvEnaMn0g3RDRPRF9LVwxq4kPKBuOHaSY3UF/czt
HzKCDBMc/L4rYgrYKYKPk8nY1qL2w7iqJsT1UMYBOI0et4bMLo8CgYEAn+Iod9UWjBQkIory6Q+3
06tLm9iMCgfPNrHCqKiwR4s7+1EMZi828oNu8piO2XjzNhbrf2jjfqL9GzYdTjM0ex/wSKOUpTZU
JkBjbnwJJVpdKV8NRBUbT+JsG9TzdPxhHlENkX7znu9QgL7hNOW03E0ICo9CoWro0R1LLMeaiDkC
gYAayvtrXVLbavAuTAaTY3Rr+vtrbYmQV/TXuk2toxZZ/ctNIT/MkMvUg+Qv6rxgGcHFgcCY/0tg
p98/hZnve5O6x81lSdLGGLzH2ixTMYPQlKS4/Ldo8QX14f6CJUN5tRg2UPv3sPvvyn+avxcu/chh
5pwWlg2MHt1vy6Wpsybp4wKBgFHXR5XHmuoLaU/RRnRsmlGcbnCREWYVB0ndBmKlLs8Ag6yqmSk5
Y+wRwVonI4BIvF5krxmiDEmHjv493hRoe6XG/I2CRpWnUL3f2cX1cg0Py35g7H58O2XR5jr8775j
bidBoCtpC7XAlLnCe69DIiheug4FtTrBafmZACEk74JpAoGANstOzkZ3NYws0z0pnvsV8I0/p8WU
AVCA0i+hMC7u3KWSeGxsJIEN4GlFHruFSV5rF8NbTdESnb7lNNPqppmakmcLtydsAgCZYfHJNJGp
hhI+4O3vf38aqkEruwsR83dzrZZi/ab2DEvuVHbVWGfQNrSV4Hq7te4Pk+MajpYaNeU=
-----END RSA PRIVATE KEY-----

View File

@@ -1,8 +1,8 @@
---
- name: known_hosts
known_hosts:
path: /root/.ssh/known_hosts
name: ssh-jump.dsfinancial.comcast.net
key: "{{ lookup('pipe', 'ssh-keyscan -t rsa ssh-jump.dsfinancial.comcast.net') }}"
become: true
---
- name: known_hosts
known_hosts:
path: /root/.ssh/known_hosts
name: ssh-jump.dsfinancial.comcast.net
key: "{{ lookup('pipe', 'ssh-keyscan -t rsa ssh-jump.dsfinancial.comcast.net') }}"
become: true

147
roles/common/tasks/main.yaml Executable file → Normal file
View File

@@ -1,68 +1,79 @@
---
- name: Upgrade all packages to the latest version
become: true
apt:
upgrade: yes
update_cache: yes
tags: apt_upgrade
- name: Create directories
file:
path: "{{ item }}"
state: directory
owner: pi
group: pi
with_items:
- /home/pi/Documents/ftp
- /home/pi/Documents/smb
- /home/pi/scripts
tags: create_dirs
- name: update hosts file
become: true
blockinfile:
dest: /etc/hosts
content: "{{ lookup('template', '{{ role_path }}/templates/hosts.j2') }}"
state: present
tags: update_hosts
- name: clean hosts file
become: true
blockinfile:
path: /etc/hosts
marker: "# {mark} ANSIBLE MANAGED BLOCK"
content: ""
tags: clean_hosts
- name: install programs and libraries
become: true
apt:
name: [ 'expect', 'ftp', 'cadaver', 'iperf', 'iperf3', 'libpcap0.8', 'libsctp1', 'libsctp-dev', 'libncurses-dev', 'libssl-dev', 'libpcap-dev', 'vim', 'mc', 'smbclient', 'ncurses-dev', 'build-essential', 'openvpn' ]
update_cache: true
state: present
tags: install_packages
- name: set hostname
become: true
hostname:
name: '{{ inventory_hostname }}'
tags: set_hostname
- name: enable openvpn
become: true
service:
name: openvpn
enabled: yes
tags: enable_openvpn
register: openvpn_enabled
- name: enable openvpn config
become: true
lineinfile:
path: /etc/default/openvpn
state: present
regexp: '^#AUTOSTART="all"'
line: 'AUTOSTART="all"'
tags: enable_openvpn
- name: start openvpn
become: true
systemd:
daemon_reload: yes
name: openvpn
state: restarted
tags: enable_openvpn
when: openvpn_enabled
---
- name: Upgrade all packages to the latest version
become: true
apt:
upgrade: yes
update_cache: yes
tags: apt_upgrade
- name: Create directories
file:
path: "{{ item }}"
state: directory
owner: pi
group: pi
with_items:
- /home/pi/Documents/ftp
- /home/pi/Documents/smb
- /home/pi/scripts
tags: create_dirs
- name: update hosts file
become: true
blockinfile:
dest: /etc/hosts
content: "{{ lookup('template', '{{ role_path }}/templates/hosts.j2') }}"
state: present
tags: update_hosts
- name: install programs and libraries
become: true
apt:
name: [ 'expect', 'ftp', 'cadaver', 'iperf', 'iperf3', 'libpcap0.8', 'libsctp1', 'libsctp-dev', 'libncurses-dev', 'libssl-dev', 'libpcap-dev', 'vim', 'mc', 'smbclient', 'ncurses-dev', 'build-essential', 'openvpn', 'lightdm', 'lxde', 'realvnc-vnc-server', 'aptitude', 'chromium-browser', 'raspberrypi-ui-mods' ]
update_cache: true
state: present
tags: install_packages
- name: set hostname
become: true
hostname:
name: '{{ inventory_hostname }}'
tags: set_hostname
- name: enable openvpn
become: true
service:
name: openvpn
enabled: yes
tags: enable_openvpn
register: openvpn_enabled
- name: enable openvpn config
become: true
lineinfile:
path: /etc/default/openvpn
state: present
regexp: '^#AUTOSTART="all"'
line: 'AUTOSTART="all"'
tags: enable_openvpn
- name: start openvpn
become: true
systemd:
daemon_reload: yes
name: openvpn
state: restarted
tags: enable_openvpn
when: openvpn_enabled
- lineinfile:
path: /etc/sudoers
state: present
regexp: '^%sudo'
line: '%sudo ALL=(ALL) NOPASSWD: ALL'
validate: 'visudo -cf %s'
become: true
tags: pi_sudo
- name: Ensure the locale exists
locale_gen:
name: en_US.UTF-8
state: present
become: yes
- name: set as default locale
command: raspi-config nonint do_change_locale en_US.UTF-8
become: yes
- name: set keyboard to us
command: raspi-config nonint do_configure_keyboard us

View File

@@ -1,7 +1,7 @@
{% for item in ansible_play_batch %}
{{ hostvars[item].ansible_host }} {{ item }}.demo.dsfinancial.com
{% endfor %}
{% for item in ansible_play_batch %}
{{ hostvars[item].ansible_host }} {{ item }}
{% endfor %}
{% for item in ansible_play_batch %}
{{ hostvars[item].ansible_host }} {{ item }}.demo.dsfinancial.com
{% endfor %}
{% for item in ansible_play_batch %}
{{ hostvars[item].ansible_host }} {{ item }}
{% endfor %}

24
roles/domainname/tasks/main.yaml Executable file → Normal file
View File

@@ -1,12 +1,12 @@
---
- lineinfile:
path: /etc/dhcpcd.conf
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { regexp: '^static\ domain_name=', line: 'static domain_name=demo.dsfinancial.com' }
- { regexp: '^static\ domain_search=', line: 'static domain_search=demo.dsfinancial.com' }
become: true
tags: update_domainname
---
- lineinfile:
path: /etc/dhcpcd.conf
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { regexp: '^static\ domain_name=', line: 'static domain_name=demo.dsfinancial.com' }
- { regexp: '^static\ domain_search=', line: 'static domain_search=demo.dsfinancial.com' }
become: true
tags: update_domainname

0
roles/facebook/files/facebook.sh Executable file → Normal file
View File

File diff suppressed because it is too large Load Diff

40
roles/facebook/tasks/main.yaml Executable file → Normal file
View File

@@ -1,20 +1,20 @@
---
- name: copy facebook script
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: pi
group: pi
mode: a+x
with_items:
- { src: "{{ role_path }}/files/facebook.sh", dest: "/home/pi/scripts/facebook.sh" }
- { src: "{{ role_path }}/files/facebook_url.list", dest: "/home/pi/Documents/facebook_url.list" }
tags: facebooktraff_script
- name: enable cron job for facebook traffic
cron:
name: "facebooktraff"
minute: "*/5"
hour: "7-18"
weekday: "1-5"
job: "/home/pi/scripts/facebook.sh"
tags: facebooktraff_cron
---
- name: copy facebook script
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: pi
group: pi
mode: a+x
with_items:
- { src: "{{ role_path }}/files/facebook.sh", dest: "/home/pi/scripts/facebook.sh" }
- { src: "{{ role_path }}/files/facebook_url.list", dest: "/home/pi/Documents/facebook_url.list" }
tags: facebooktraff_script
- name: enable cron job for facebook traffic
cron:
name: "facebooktraff"
minute: "*/5"
hour: "7-18"
weekday: "1-5"
job: "/home/pi/scripts/facebook.sh"
tags: facebooktraff_cron

0
roles/ftpclient/files/ftp-session.sh Executable file → Normal file
View File

34
roles/ftpclient/tasks/main.yaml Executable file → Normal file
View File

@@ -1,17 +1,17 @@
---
- name: enable cron job for ftp traffic
cron:
name: "ftptraff"
minute: "0"
hour: "7-18/2"
weekday: "1-5"
job: "/usr/bin/perl -e 'sleep int rand 7199' && /home/pi/scripts/ftp-session.sh"
tags: ftptraff_cron
- name: copy ftp-session.sh to scripts directory
copy:
src: "{{ role_path }}/files/ftp-session.sh"
dest: /home/pi/scripts/ftp-session.sh
owner: pi
group: pi
mode: a+x
tags: ftptraff_script
---
- name: enable cron job for ftp traffic
cron:
name: "ftptraff"
minute: "0"
hour: "7-18/2"
weekday: "1-5"
job: "/usr/bin/perl -e 'sleep int rand 7199' && /home/pi/scripts/ftp-session.sh"
tags: ftptraff_cron
- name: copy ftp-session.sh to scripts directory
copy:
src: "{{ role_path }}/files/ftp-session.sh"
dest: /home/pi/scripts/ftp-session.sh
owner: pi
group: pi
mode: a+x
tags: ftptraff_script

48
roles/netflows/tasks/main.yaml Executable file → Normal file
View File

@@ -1,24 +1,24 @@
---
- name: Install fprobe Package
become: yes
apt:
name: ['fprobe']
state: present
update_cache: true
tags: install_fprobe
- lineinfile:
path: /etc/default/fprobe
state: present
backrefs: yes
regexp: '^FLOW_COLLECTOR='
line: 'FLOW_COLLECTOR="192.168.201.11:2055"'
become: true
tags: configure_fprobe
- name: enable fprobe service and ensure it is not masked
systemd:
name: fprobe
enabled: yes
masked: no
state: restarted
tags: enable_fprobe
become: true
---
- name: Install fprobe Package
become: yes
apt:
name: ['fprobe']
state: present
update_cache: true
tags: install_fprobe
- lineinfile:
path: /etc/default/fprobe
state: present
backrefs: yes
regexp: '^FLOW_COLLECTOR='
line: 'FLOW_COLLECTOR="192.168.201.11:2055"'
become: true
tags: configure_fprobe
- name: enable fprobe service and ensure it is not masked
systemd:
name: fprobe
enabled: yes
masked: no
state: restarted
tags: enable_fprobe
become: true

818
roles/nrpe/files/check_mem.pl Executable file → Normal file
View File

@@ -1,409 +1,409 @@
#!/usr/bin/perl -w
# Heavily based on the script from:
# check_mem.pl Copyright (C) 2000 Dan Larsson <dl@tyfon.net>
# heavily modified by
# Justin Ellison <justin@techadvise.com>
#
# The MIT License (MIT)
# Copyright (c) 2011 justin@techadvise.com
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
# OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# Tell Perl what we need to use
use strict;
use Getopt::Std;
#TODO - Convert to Nagios::Plugin
#TODO - Use an alarm
# Predefined exit codes for Nagios
use vars qw($opt_c $opt_f $opt_u $opt_w $opt_C $opt_v $opt_h %exit_codes);
%exit_codes = ('UNKNOWN' , 3,
'OK' , 0,
'WARNING' , 1,
'CRITICAL', 2,
);
# Get our variables, do our checking:
init();
# Get the numbers:
my ($free_memory_kb,$used_memory_kb,$caches_kb,$hugepages_kb) = get_memory_info();
print "$free_memory_kb Free\n$used_memory_kb Used\n$caches_kb Cache\n" if ($opt_v);
print "$hugepages_kb Hugepages\n" if ($opt_v and $opt_h);
if ($opt_C) { #Do we count caches as free?
$used_memory_kb -= $caches_kb;
$free_memory_kb += $caches_kb;
}
if ($opt_h) {
$used_memory_kb -= $hugepages_kb;
}
print "$used_memory_kb Used (after Hugepages)\n" if ($opt_v);
# Round to the nearest KB
$free_memory_kb = sprintf('%d',$free_memory_kb);
$used_memory_kb = sprintf('%d',$used_memory_kb);
$caches_kb = sprintf('%d',$caches_kb);
# Tell Nagios what we came up with
tell_nagios($used_memory_kb,$free_memory_kb,$caches_kb,$hugepages_kb);
sub tell_nagios {
my ($used,$free,$caches,$hugepages) = @_;
# Calculate Total Memory
my $total = $free + $used;
print "$total Total\n" if ($opt_v);
my $perf_warn;
my $perf_crit;
if ( $opt_u ) {
$perf_warn = int(${total} * $opt_w / 100);
$perf_crit = int(${total} * $opt_c / 100);
} else {
$perf_warn = int(${total} * ( 100 - $opt_w ) / 100);
$perf_crit = int(${total} * ( 100 - $opt_c ) / 100);
}
my $perfdata = "|TOTAL=${total}KB;;;; USED=${used}KB;${perf_warn};${perf_crit};; FREE=${free}KB;;;; CACHES=${caches}KB;;;;";
$perfdata .= " HUGEPAGES=${hugepages}KB;;;;" if ($opt_h);
if ($opt_f) {
my $percent = sprintf "%.1f", ($free / $total * 100);
if ($percent <= $opt_c) {
finish("CRITICAL - $percent% ($free kB) free!$perfdata",$exit_codes{'CRITICAL'});
}
elsif ($percent <= $opt_w) {
finish("WARNING - $percent% ($free kB) free!$perfdata",$exit_codes{'WARNING'});
}
else {
finish("OK - $percent% ($free kB) free.$perfdata",$exit_codes{'OK'});
}
}
elsif ($opt_u) {
my $percent = sprintf "%.1f", ($used / $total * 100);
if ($percent >= $opt_c) {
finish("CRITICAL - $percent% ($used kB) used!$perfdata",$exit_codes{'CRITICAL'});
}
elsif ($percent >= $opt_w) {
finish("WARNING - $percent% ($used kB) used!$perfdata",$exit_codes{'WARNING'});
}
else {
finish("OK - $percent% ($used kB) used.$perfdata",$exit_codes{'OK'});
}
}
}
# Show usage
sub usage() {
print "\ncheck_mem.pl v1.0 - Nagios Plugin\n\n";
print "usage:\n";
print " check_mem.pl -<f|u> -w <warnlevel> -c <critlevel>\n\n";
print "options:\n";
print " -f Check FREE memory\n";
print " -u Check USED memory\n";
print " -C Count OS caches as FREE memory\n";
print " -h Remove hugepages from the total memory count\n";
print " -w PERCENT Percent free/used when to warn\n";
print " -c PERCENT Percent free/used when critical\n";
print "\nCopyright (C) 2000 Dan Larsson <dl\@tyfon.net>\n";
print "check_mem.pl comes with absolutely NO WARRANTY either implied or explicit\n";
print "This program is licensed under the terms of the\n";
print "MIT License (check source code for details)\n";
exit $exit_codes{'UNKNOWN'};
}
sub get_memory_info {
my $used_memory_kb = 0;
my $free_memory_kb = 0;
my $total_memory_kb = 0;
my $caches_kb = 0;
my $hugepages_nr = 0;
my $hugepages_size = 0;
my $hugepages_kb = 0;
my $uname;
if ( -e '/usr/bin/uname') {
$uname = `/usr/bin/uname -a`;
}
elsif ( -e '/bin/uname') {
$uname = `/bin/uname -a`;
}
else {
die "Unable to find uname in /usr/bin or /bin!\n";
}
print "uname returns $uname" if ($opt_v);
if ( $uname =~ /Linux/ ) {
my @meminfo = `/bin/cat /proc/meminfo`;
foreach (@meminfo) {
chomp;
if (/^Mem(Total|Free):\s+(\d+) kB/) {
my $counter_name = $1;
if ($counter_name eq 'Free') {
$free_memory_kb = $2;
}
elsif ($counter_name eq 'Total') {
$total_memory_kb = $2;
}
}
elsif (/^(Buffers|Cached|SReclaimable):\s+(\d+) kB/) {
$caches_kb += $2;
}
elsif (/^Shmem:\s+(\d+) kB/) {
$caches_kb -= $1;
}
# These variables will most likely be overwritten once we look into
# /sys/kernel/mm/hugepages, unless we are running on linux <2.6.27
# and have to rely on them
elsif (/^HugePages_Total:\s+(\d+)/) {
$hugepages_nr = $1;
}
elsif (/^Hugepagesize:\s+(\d+) kB/) {
$hugepages_size = $1;
}
}
$hugepages_kb = $hugepages_nr * $hugepages_size;
$used_memory_kb = $total_memory_kb - $free_memory_kb;
# Read hugepages info from the newer sysfs interface if available
my $hugepages_sysfs_dir = '/sys/kernel/mm/hugepages';
if ( -d $hugepages_sysfs_dir ) {
# Reset what we read from /proc/meminfo
$hugepages_kb = 0;
opendir(my $dh, $hugepages_sysfs_dir)
|| die "Can't open $hugepages_sysfs_dir: $!";
while (my $entry = readdir $dh) {
if ($entry =~ /^hugepages-(\d+)kB/) {
$hugepages_size = $1;
my $hugepages_nr_file = "$hugepages_sysfs_dir/$entry/nr_hugepages";
open(my $fh, '<', $hugepages_nr_file)
|| die "Can't open $hugepages_nr_file for reading: $!";
$hugepages_nr = <$fh>;
close($fh);
$hugepages_kb += $hugepages_nr * $hugepages_size;
}
}
closedir($dh);
}
}
elsif ( $uname =~ /HP-UX/ ) {
# HP-UX, thanks to Christoph Fürstaller
my @meminfo = `/usr/bin/sudo /usr/local/bin/kmeminfo`;
foreach (@meminfo) {
chomp;
if (/^Physical memory\s\s+=\s+(\d+)\s+(\d+.\d)g/) {
$total_memory_kb = ($2 * 1024 * 1024);
}
elsif (/^Free memory\s\s+=\s+(\d+)\s+(\d+.\d)g/) {
$free_memory_kb = ($2 * 1024 * 1024);
}
}
$used_memory_kb = $total_memory_kb - $free_memory_kb;
}
elsif ( $uname =~ /FreeBSD/ ) {
# The FreeBSD case. 2013-03-19 www.claudiokuenzler.com
# free mem = Inactive*Page Size + Cache*Page Size + Free*Page Size
my $pagesize = `sysctl vm.stats.vm.v_page_size`;
$pagesize =~ s/[^0-9]//g;
my $mem_inactive = 0;
my $mem_cache = 0;
my $mem_free = 0;
my $mem_total = 0;
my $free_memory = 0;
my @meminfo = `/sbin/sysctl vm.stats.vm`;
foreach (@meminfo) {
chomp;
if (/^vm.stats.vm.v_inactive_count:\s+(\d+)/) {
$mem_inactive = ($1 * $pagesize);
}
elsif (/^vm.stats.vm.v_cache_count:\s+(\d+)/) {
$mem_cache = ($1 * $pagesize);
}
elsif (/^vm.stats.vm.v_free_count:\s+(\d+)/) {
$mem_free = ($1 * $pagesize);
}
elsif (/^vm.stats.vm.v_page_count:\s+(\d+)/) {
$mem_total = ($1 * $pagesize);
}
}
$free_memory = $mem_inactive + $mem_cache + $mem_free;
$free_memory_kb = ( $free_memory / 1024);
$total_memory_kb = ( $mem_total / 1024);
$used_memory_kb = $total_memory_kb - $free_memory_kb;
$caches_kb = ($mem_cache / 1024);
}
elsif ( $uname =~ /joyent/ ) {
# The SmartOS case. 2014-01-10 www.claudiokuenzler.com
# free mem = pagesfree * pagesize
my $pagesize = `pagesize`;
my $phys_pages = `kstat -p unix:0:system_pages:pagestotal | awk '{print \$NF}'`;
my $free_pages = `kstat -p unix:0:system_pages:pagesfree | awk '{print \$NF}'`;
my $arc_size = `kstat -p zfs:0:arcstats:size | awk '{print \$NF}'`;
my $arc_size_kb = $arc_size / 1024;
print "Pagesize is $pagesize" if ($opt_v);
print "Total pages is $phys_pages" if ($opt_v);
print "Free pages is $free_pages" if ($opt_v);
print "Arc size is $arc_size" if ($opt_v);
$caches_kb += $arc_size_kb;
$total_memory_kb = $phys_pages * $pagesize / 1024;
$free_memory_kb = $free_pages * $pagesize / 1024;
$used_memory_kb = $total_memory_kb - $free_memory_kb;
}
elsif ( $uname =~ /SunOS/ ) {
eval "use Sun::Solaris::Kstat";
if ($@) { #Kstat not available
if ($opt_C) {
print "You can't report on Solaris caches without Sun::Solaris::Kstat available!\n";
exit $exit_codes{UNKNOWN};
}
my @vmstat = `/usr/bin/vmstat 1 2`;
my $line;
foreach (@vmstat) {
chomp;
$line = $_;
}
$free_memory_kb = (split(/ /,$line))[5] / 1024;
my @prtconf = `/usr/sbin/prtconf`;
foreach (@prtconf) {
if (/^Memory size: (\d+) Megabytes/) {
$total_memory_kb = $1 * 1024;
}
}
$used_memory_kb = $total_memory_kb - $free_memory_kb;
}
else { # We have kstat
my $kstat = Sun::Solaris::Kstat->new();
my $phys_pages = ${kstat}->{unix}->{0}->{system_pages}->{physmem};
my $free_pages = ${kstat}->{unix}->{0}->{system_pages}->{freemem};
# We probably should account for UFS caching here, but it's unclear
# to me how to determine UFS's cache size. There's inode_cache,
# and maybe the physmem variable in the system_pages module??
# In the real world, it looks to be so small as not to really matter,
# so we don't grab it. If someone can give me code that does this,
# I'd be glad to put it in.
my $arc_size = (exists ${kstat}->{zfs} && ${kstat}->{zfs}->{0}->{arcstats}->{size}) ?
${kstat}->{zfs}->{0}->{arcstats}->{size} / 1024
: 0;
$caches_kb += $arc_size;
my $pagesize = `pagesize`;
$total_memory_kb = $phys_pages * $pagesize / 1024;
$free_memory_kb = $free_pages * $pagesize / 1024;
$used_memory_kb = $total_memory_kb - $free_memory_kb;
}
}
elsif ( $uname =~ /Darwin/ ) {
$total_memory_kb = (split(/ /,`/usr/sbin/sysctl hw.memsize`))[1]/1024;
my $pagesize = (split(/ /,`/usr/sbin/sysctl hw.pagesize`))[1];
$caches_kb = 0;
my @vm_stat = `/usr/bin/vm_stat`;
foreach (@vm_stat) {
chomp;
if (/^(Pages free):\s+(\d+)\.$/) {
$free_memory_kb = $2*$pagesize/1024;
}
# 'caching' concept works different on MACH
# this should be a reasonable approximation
elsif (/^Pages (inactive|purgable):\s+(\d+).$/) {
$caches_kb += $2*$pagesize/1024;
}
}
$used_memory_kb = $total_memory_kb - $free_memory_kb;
}
elsif ( $uname =~ /AIX/ ) {
my @meminfo = `/usr/bin/vmstat -vh`;
foreach (@meminfo) {
chomp;
if (/^\s*([0-9.]+)\s+(.*)/) {
my $counter_name = $2;
if ($counter_name eq 'memory pages') {
$total_memory_kb = $1*4;
}
if ($counter_name eq 'free pages') {
$free_memory_kb = $1*4;
}
if ($counter_name eq 'file pages') {
$caches_kb = $1*4;
}
if ($counter_name eq 'Number of 4k page frames loaned') {
$free_memory_kb += $1*4;
}
}
}
$used_memory_kb = $total_memory_kb - $free_memory_kb;
}
else {
if ($opt_C) {
print "You can't report on $uname caches!\n";
exit $exit_codes{UNKNOWN};
}
my $command_line = `vmstat | tail -1 | awk '{print \$4,\$5}'`;
chomp $command_line;
my @memlist = split(/ /, $command_line);
# Define the calculating scalars
$used_memory_kb = $memlist[0]/1024;
$free_memory_kb = $memlist[1]/1024;
$total_memory_kb = $used_memory_kb + $free_memory_kb;
}
return ($free_memory_kb,$used_memory_kb,$caches_kb,$hugepages_kb);
}
sub init {
# Get the options
if ($#ARGV le 0) {
&usage;
}
else {
getopts('c:fuChvw:');
}
# Shortcircuit the switches
if (!$opt_w or $opt_w == 0 or !$opt_c or $opt_c == 0) {
print "*** You must define WARN and CRITICAL levels!\n";
&usage;
}
elsif (!$opt_f and !$opt_u) {
print "*** You must select to monitor either USED or FREE memory!\n";
&usage;
}
# Check if levels are sane
if ($opt_w <= $opt_c and $opt_f) {
print "*** WARN level must not be less than CRITICAL when checking FREE memory!\n";
&usage;
}
elsif ($opt_w >= $opt_c and $opt_u) {
print "*** WARN level must not be greater than CRITICAL when checking USED memory!\n";
&usage;
}
}
sub finish {
my ($msg,$state) = @_;
print "$msg\n";
exit $state;
}
#!/usr/bin/perl -w
# Heavily based on the script from:
# check_mem.pl Copyright (C) 2000 Dan Larsson <dl@tyfon.net>
# heavily modified by
# Justin Ellison <justin@techadvise.com>
#
# The MIT License (MIT)
# Copyright (c) 2011 justin@techadvise.com
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all copies
# or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
# OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
# Tell Perl what we need to use
use strict;
use Getopt::Std;
#TODO - Convert to Nagios::Plugin
#TODO - Use an alarm
# Predefined exit codes for Nagios
use vars qw($opt_c $opt_f $opt_u $opt_w $opt_C $opt_v $opt_h %exit_codes);
%exit_codes = ('UNKNOWN' , 3,
'OK' , 0,
'WARNING' , 1,
'CRITICAL', 2,
);
# Get our variables, do our checking:
init();
# Get the numbers:
my ($free_memory_kb,$used_memory_kb,$caches_kb,$hugepages_kb) = get_memory_info();
print "$free_memory_kb Free\n$used_memory_kb Used\n$caches_kb Cache\n" if ($opt_v);
print "$hugepages_kb Hugepages\n" if ($opt_v and $opt_h);
if ($opt_C) { #Do we count caches as free?
$used_memory_kb -= $caches_kb;
$free_memory_kb += $caches_kb;
}
if ($opt_h) {
$used_memory_kb -= $hugepages_kb;
}
print "$used_memory_kb Used (after Hugepages)\n" if ($opt_v);
# Round to the nearest KB
$free_memory_kb = sprintf('%d',$free_memory_kb);
$used_memory_kb = sprintf('%d',$used_memory_kb);
$caches_kb = sprintf('%d',$caches_kb);
# Tell Nagios what we came up with
tell_nagios($used_memory_kb,$free_memory_kb,$caches_kb,$hugepages_kb);
sub tell_nagios {
my ($used,$free,$caches,$hugepages) = @_;
# Calculate Total Memory
my $total = $free + $used;
print "$total Total\n" if ($opt_v);
my $perf_warn;
my $perf_crit;
if ( $opt_u ) {
$perf_warn = int(${total} * $opt_w / 100);
$perf_crit = int(${total} * $opt_c / 100);
} else {
$perf_warn = int(${total} * ( 100 - $opt_w ) / 100);
$perf_crit = int(${total} * ( 100 - $opt_c ) / 100);
}
my $perfdata = "|TOTAL=${total}KB;;;; USED=${used}KB;${perf_warn};${perf_crit};; FREE=${free}KB;;;; CACHES=${caches}KB;;;;";
$perfdata .= " HUGEPAGES=${hugepages}KB;;;;" if ($opt_h);
if ($opt_f) {
my $percent = sprintf "%.1f", ($free / $total * 100);
if ($percent <= $opt_c) {
finish("CRITICAL - $percent% ($free kB) free!$perfdata",$exit_codes{'CRITICAL'});
}
elsif ($percent <= $opt_w) {
finish("WARNING - $percent% ($free kB) free!$perfdata",$exit_codes{'WARNING'});
}
else {
finish("OK - $percent% ($free kB) free.$perfdata",$exit_codes{'OK'});
}
}
elsif ($opt_u) {
my $percent = sprintf "%.1f", ($used / $total * 100);
if ($percent >= $opt_c) {
finish("CRITICAL - $percent% ($used kB) used!$perfdata",$exit_codes{'CRITICAL'});
}
elsif ($percent >= $opt_w) {
finish("WARNING - $percent% ($used kB) used!$perfdata",$exit_codes{'WARNING'});
}
else {
finish("OK - $percent% ($used kB) used.$perfdata",$exit_codes{'OK'});
}
}
}
# Show usage
sub usage() {
print "\ncheck_mem.pl v1.0 - Nagios Plugin\n\n";
print "usage:\n";
print " check_mem.pl -<f|u> -w <warnlevel> -c <critlevel>\n\n";
print "options:\n";
print " -f Check FREE memory\n";
print " -u Check USED memory\n";
print " -C Count OS caches as FREE memory\n";
print " -h Remove hugepages from the total memory count\n";
print " -w PERCENT Percent free/used when to warn\n";
print " -c PERCENT Percent free/used when critical\n";
print "\nCopyright (C) 2000 Dan Larsson <dl\@tyfon.net>\n";
print "check_mem.pl comes with absolutely NO WARRANTY either implied or explicit\n";
print "This program is licensed under the terms of the\n";
print "MIT License (check source code for details)\n";
exit $exit_codes{'UNKNOWN'};
}
sub get_memory_info {
my $used_memory_kb = 0;
my $free_memory_kb = 0;
my $total_memory_kb = 0;
my $caches_kb = 0;
my $hugepages_nr = 0;
my $hugepages_size = 0;
my $hugepages_kb = 0;
my $uname;
if ( -e '/usr/bin/uname') {
$uname = `/usr/bin/uname -a`;
}
elsif ( -e '/bin/uname') {
$uname = `/bin/uname -a`;
}
else {
die "Unable to find uname in /usr/bin or /bin!\n";
}
print "uname returns $uname" if ($opt_v);
if ( $uname =~ /Linux/ ) {
my @meminfo = `/bin/cat /proc/meminfo`;
foreach (@meminfo) {
chomp;
if (/^Mem(Total|Free):\s+(\d+) kB/) {
my $counter_name = $1;
if ($counter_name eq 'Free') {
$free_memory_kb = $2;
}
elsif ($counter_name eq 'Total') {
$total_memory_kb = $2;
}
}
elsif (/^(Buffers|Cached|SReclaimable):\s+(\d+) kB/) {
$caches_kb += $2;
}
elsif (/^Shmem:\s+(\d+) kB/) {
$caches_kb -= $1;
}
# These variables will most likely be overwritten once we look into
# /sys/kernel/mm/hugepages, unless we are running on linux <2.6.27
# and have to rely on them
elsif (/^HugePages_Total:\s+(\d+)/) {
$hugepages_nr = $1;
}
elsif (/^Hugepagesize:\s+(\d+) kB/) {
$hugepages_size = $1;
}
}
$hugepages_kb = $hugepages_nr * $hugepages_size;
$used_memory_kb = $total_memory_kb - $free_memory_kb;
# Read hugepages info from the newer sysfs interface if available
my $hugepages_sysfs_dir = '/sys/kernel/mm/hugepages';
if ( -d $hugepages_sysfs_dir ) {
# Reset what we read from /proc/meminfo
$hugepages_kb = 0;
opendir(my $dh, $hugepages_sysfs_dir)
|| die "Can't open $hugepages_sysfs_dir: $!";
while (my $entry = readdir $dh) {
if ($entry =~ /^hugepages-(\d+)kB/) {
$hugepages_size = $1;
my $hugepages_nr_file = "$hugepages_sysfs_dir/$entry/nr_hugepages";
open(my $fh, '<', $hugepages_nr_file)
|| die "Can't open $hugepages_nr_file for reading: $!";
$hugepages_nr = <$fh>;
close($fh);
$hugepages_kb += $hugepages_nr * $hugepages_size;
}
}
closedir($dh);
}
}
elsif ( $uname =~ /HP-UX/ ) {
# HP-UX, thanks to Christoph Fürstaller
my @meminfo = `/usr/bin/sudo /usr/local/bin/kmeminfo`;
foreach (@meminfo) {
chomp;
if (/^Physical memory\s\s+=\s+(\d+)\s+(\d+.\d)g/) {
$total_memory_kb = ($2 * 1024 * 1024);
}
elsif (/^Free memory\s\s+=\s+(\d+)\s+(\d+.\d)g/) {
$free_memory_kb = ($2 * 1024 * 1024);
}
}
$used_memory_kb = $total_memory_kb - $free_memory_kb;
}
elsif ( $uname =~ /FreeBSD/ ) {
# The FreeBSD case. 2013-03-19 www.claudiokuenzler.com
# free mem = Inactive*Page Size + Cache*Page Size + Free*Page Size
my $pagesize = `sysctl vm.stats.vm.v_page_size`;
$pagesize =~ s/[^0-9]//g;
my $mem_inactive = 0;
my $mem_cache = 0;
my $mem_free = 0;
my $mem_total = 0;
my $free_memory = 0;
my @meminfo = `/sbin/sysctl vm.stats.vm`;
foreach (@meminfo) {
chomp;
if (/^vm.stats.vm.v_inactive_count:\s+(\d+)/) {
$mem_inactive = ($1 * $pagesize);
}
elsif (/^vm.stats.vm.v_cache_count:\s+(\d+)/) {
$mem_cache = ($1 * $pagesize);
}
elsif (/^vm.stats.vm.v_free_count:\s+(\d+)/) {
$mem_free = ($1 * $pagesize);
}
elsif (/^vm.stats.vm.v_page_count:\s+(\d+)/) {
$mem_total = ($1 * $pagesize);
}
}
$free_memory = $mem_inactive + $mem_cache + $mem_free;
$free_memory_kb = ( $free_memory / 1024);
$total_memory_kb = ( $mem_total / 1024);
$used_memory_kb = $total_memory_kb - $free_memory_kb;
$caches_kb = ($mem_cache / 1024);
}
elsif ( $uname =~ /joyent/ ) {
# The SmartOS case. 2014-01-10 www.claudiokuenzler.com
# free mem = pagesfree * pagesize
my $pagesize = `pagesize`;
my $phys_pages = `kstat -p unix:0:system_pages:pagestotal | awk '{print \$NF}'`;
my $free_pages = `kstat -p unix:0:system_pages:pagesfree | awk '{print \$NF}'`;
my $arc_size = `kstat -p zfs:0:arcstats:size | awk '{print \$NF}'`;
my $arc_size_kb = $arc_size / 1024;
print "Pagesize is $pagesize" if ($opt_v);
print "Total pages is $phys_pages" if ($opt_v);
print "Free pages is $free_pages" if ($opt_v);
print "Arc size is $arc_size" if ($opt_v);
$caches_kb += $arc_size_kb;
$total_memory_kb = $phys_pages * $pagesize / 1024;
$free_memory_kb = $free_pages * $pagesize / 1024;
$used_memory_kb = $total_memory_kb - $free_memory_kb;
}
elsif ( $uname =~ /SunOS/ ) {
eval "use Sun::Solaris::Kstat";
if ($@) { #Kstat not available
if ($opt_C) {
print "You can't report on Solaris caches without Sun::Solaris::Kstat available!\n";
exit $exit_codes{UNKNOWN};
}
my @vmstat = `/usr/bin/vmstat 1 2`;
my $line;
foreach (@vmstat) {
chomp;
$line = $_;
}
$free_memory_kb = (split(/ /,$line))[5] / 1024;
my @prtconf = `/usr/sbin/prtconf`;
foreach (@prtconf) {
if (/^Memory size: (\d+) Megabytes/) {
$total_memory_kb = $1 * 1024;
}
}
$used_memory_kb = $total_memory_kb - $free_memory_kb;
}
else { # We have kstat
my $kstat = Sun::Solaris::Kstat->new();
my $phys_pages = ${kstat}->{unix}->{0}->{system_pages}->{physmem};
my $free_pages = ${kstat}->{unix}->{0}->{system_pages}->{freemem};
# We probably should account for UFS caching here, but it's unclear
# to me how to determine UFS's cache size. There's inode_cache,
# and maybe the physmem variable in the system_pages module??
# In the real world, it looks to be so small as not to really matter,
# so we don't grab it. If someone can give me code that does this,
# I'd be glad to put it in.
my $arc_size = (exists ${kstat}->{zfs} && ${kstat}->{zfs}->{0}->{arcstats}->{size}) ?
${kstat}->{zfs}->{0}->{arcstats}->{size} / 1024
: 0;
$caches_kb += $arc_size;
my $pagesize = `pagesize`;
$total_memory_kb = $phys_pages * $pagesize / 1024;
$free_memory_kb = $free_pages * $pagesize / 1024;
$used_memory_kb = $total_memory_kb - $free_memory_kb;
}
}
elsif ( $uname =~ /Darwin/ ) {
$total_memory_kb = (split(/ /,`/usr/sbin/sysctl hw.memsize`))[1]/1024;
my $pagesize = (split(/ /,`/usr/sbin/sysctl hw.pagesize`))[1];
$caches_kb = 0;
my @vm_stat = `/usr/bin/vm_stat`;
foreach (@vm_stat) {
chomp;
if (/^(Pages free):\s+(\d+)\.$/) {
$free_memory_kb = $2*$pagesize/1024;
}
# 'caching' concept works different on MACH
# this should be a reasonable approximation
elsif (/^Pages (inactive|purgable):\s+(\d+).$/) {
$caches_kb += $2*$pagesize/1024;
}
}
$used_memory_kb = $total_memory_kb - $free_memory_kb;
}
elsif ( $uname =~ /AIX/ ) {
my @meminfo = `/usr/bin/vmstat -vh`;
foreach (@meminfo) {
chomp;
if (/^\s*([0-9.]+)\s+(.*)/) {
my $counter_name = $2;
if ($counter_name eq 'memory pages') {
$total_memory_kb = $1*4;
}
if ($counter_name eq 'free pages') {
$free_memory_kb = $1*4;
}
if ($counter_name eq 'file pages') {
$caches_kb = $1*4;
}
if ($counter_name eq 'Number of 4k page frames loaned') {
$free_memory_kb += $1*4;
}
}
}
$used_memory_kb = $total_memory_kb - $free_memory_kb;
}
else {
if ($opt_C) {
print "You can't report on $uname caches!\n";
exit $exit_codes{UNKNOWN};
}
my $command_line = `vmstat | tail -1 | awk '{print \$4,\$5}'`;
chomp $command_line;
my @memlist = split(/ /, $command_line);
# Define the calculating scalars
$used_memory_kb = $memlist[0]/1024;
$free_memory_kb = $memlist[1]/1024;
$total_memory_kb = $used_memory_kb + $free_memory_kb;
}
return ($free_memory_kb,$used_memory_kb,$caches_kb,$hugepages_kb);
}
sub init {
# Get the options
if ($#ARGV le 0) {
&usage;
}
else {
getopts('c:fuChvw:');
}
# Shortcircuit the switches
if (!$opt_w or $opt_w == 0 or !$opt_c or $opt_c == 0) {
print "*** You must define WARN and CRITICAL levels!\n";
&usage;
}
elsif (!$opt_f and !$opt_u) {
print "*** You must select to monitor either USED or FREE memory!\n";
&usage;
}
# Check if levels are sane
if ($opt_w <= $opt_c and $opt_f) {
print "*** WARN level must not be less than CRITICAL when checking FREE memory!\n";
&usage;
}
elsif ($opt_w >= $opt_c and $opt_u) {
print "*** WARN level must not be greater than CRITICAL when checking USED memory!\n";
&usage;
}
}
sub finish {
my ($msg,$state) = @_;
print "$msg\n";
exit $state;
}

View File

@@ -1,314 +1,314 @@
#############################################################################
# Sample NRPE Config File
# Written by: Ethan Galstad (nagios@nagios.org)
#
# Last Modified: 2016-05-10
#
# NOTES:
# This is a sample configuration file for the NRPE daemon. It needs to be
# located on the remote host that is running the NRPE daemon, not the host
# from which the check_nrpe client is being executed.
#############################################################################
# LOG FACILITY
# The syslog facility that should be used for logging purposes.
log_facility=daemon
# DEBUGGING OPTION
# This option determines whether or not debugging messages are logged to the
# syslog facility.
# Values: 0=debugging off, 1=debugging on
debug=0
# PID FILE
# The name of the file in which the NRPE daemon should write it's process ID
# number. The file is only written if the NRPE daemon is started by the root
# user and is running in standalone mode.
pid_file=/var/run/nagios/nrpe.pid
# PORT NUMBER
# Port number we should wait for connections on.
# NOTE: This must be a non-priviledged port (i.e. > 1024).
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
server_port=5666
# SERVER ADDRESS
# Address that nrpe should bind to in case there are more than one interface
# and you do not want nrpe to bind on all interfaces.
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
#server_address=127.0.0.1
# LISTEN QUEUE SIZE
# Listen queue size (backlog) for serving incoming connections.
# You may want to increase this value under high load.
#listen_queue_size=5
# NRPE USER
# This determines the effective user that the NRPE daemon should run as.
# You can either supply a username or a UID.
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
nrpe_user=nagios
# NRPE GROUP
# This determines the effective group that the NRPE daemon should run as.
# You can either supply a group name or a GID.
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
nrpe_group=nagios
# ALLOWED HOST ADDRESSES
# This is an optional comma-delimited list of IP address or hostnames
# that are allowed to talk to the NRPE daemon. Network addresses with a bit mask
# (i.e. 192.168.1.0/24) are also supported. Hostname wildcards are not currently
# supported.
#
# Note: The daemon only does rudimentary checking of the client's IP
# address. I would highly recommend adding entries in your /etc/hosts.allow
# file to allow only the specified host to connect to the port
# you are running this daemon on.
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
allowed_hosts=192.168.201.2
# COMMAND ARGUMENT PROCESSING
# This option determines whether or not the NRPE daemon will allow clients
# to specify arguments to commands that are executed. This option only works
# if the daemon was configured with the --enable-command-args configure script
# option.
#
# *** ENABLING THIS OPTION IS A SECURITY RISK! ***
# Read the SECURITY file for information on some of the security implications
# of enabling this variable.
#
# Values: 0=do not allow arguments, 1=allow command arguments
dont_blame_nrpe=1
# BASH COMMAND SUBTITUTION
# This option determines whether or not the NRPE daemon will allow clients
# to specify arguments that contain bash command substitutions of the form
# $(...). This option only works if the daemon was configured with both
# the --enable-command-args and --enable-bash-command-substitution configure
# script options.
#
# *** ENABLING THIS OPTION IS A HIGH SECURITY RISK! ***
# Read the SECURITY file for information on some of the security implications
# of enabling this variable.
#
# Values: 0=do not allow bash command substitutions,
# 1=allow bash command substitutions
allow_bash_command_substitution=0
# COMMAND PREFIX
# This option allows you to prefix all commands with a user-defined string.
# A space is automatically added between the specified prefix string and the
# command line from the command definition.
#
# *** THIS EXAMPLE MAY POSE A POTENTIAL SECURITY RISK, SO USE WITH CAUTION! ***
# Usage scenario:
# Execute restricted commmands using sudo. For this to work, you need to add
# the nagios user to your /etc/sudoers. An example entry for alllowing
# execution of the plugins from might be:
#
# nagios ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/
#
# This lets the nagios user run all commands in that directory (and only them)
# without asking for a password. If you do this, make sure you don't give
# random users write access to that directory or its contents!
# command_prefix=/usr/bin/sudo
# COMMAND TIMEOUT
# This specifies the maximum number of seconds that the NRPE daemon will
# allow plugins to finish executing before killing them off.
command_timeout=60
# CONNECTION TIMEOUT
# This specifies the maximum number of seconds that the NRPE daemon will
# wait for a connection to be established before exiting. This is sometimes
# seen where a network problem stops the SSL being established even though
# all network sessions are connected. This causes the nrpe daemons to
# accumulate, eating system resources. Do not set this too low.
connection_timeout=300
# WEAK RANDOM SEED OPTION
# This directive allows you to use SSL even if your system does not have
# a /dev/random or /dev/urandom (on purpose or because the necessary patches
# were not applied). The random number generator will be seeded from a file
# which is either a file pointed to by the environment valiable $RANDFILE
# or $HOME/.rnd. If neither exists, the pseudo random number generator will
# be initialized and a warning will be issued.
# Values: 0=only seed from /dev/[u]random, 1=also seed from weak randomness
allow_weak_random_seed=1
# SSL/TLS OPTIONS
# These directives allow you to specify how to use SSL/TLS.
# SSL VERSION
# This can be any of: SSLv2 (only use SSLv2), SSLv2+ (use any version),
# SSLv3 (only use SSLv3), SSLv3+ (use SSLv3 or above), TLSv1 (only use
# TLSv1), TLSv1+ (use TLSv1 or above), TLSv1.1 (only use TLSv1.1),
# TLSv1.1+ (use TLSv1.1 or above), TLSv1.2 (only use TLSv1.2),
# TLSv1.2+ (use TLSv1.2 or above)
# If an "or above" version is used, the best will be negotiated. So if both
# ends are able to do TLSv1.2 and use specify SSLv2, you will get TLSv1.2.
#ssl_version=SSLv2+
# SSL USE ADH
# This is for backward compatibility and is DEPRECATED. Set to 1 to enable
# ADH or 2 to require ADH. 1 is currently the default but will be changed
# in a later version.
#ssl_use_adh=1
# SSL CIPHER LIST
# This lists which ciphers can be used. For backward compatibility, this
# defaults to 'ssl_cipher_list=ALL:!MD5:@STRENGTH' in this version but
# will be changed to something like the example below in a later version of NRPE.
#ssl_cipher_list=ALL:!MD5:@STRENGTH
#ssl_cipher_list=ALL:!aNULL:!eNULL:!SSLv2:!LOW:!EXP:!RC4:!MD5:@STRENGTH
# SSL Certificate and Private Key Files
#ssl_cacert_file=/etc/ssl/servercerts/ca-cert.pem
#ssl_cert_file=/etc/ssl/servercerts/nagios-cert.pem
#ssl_privatekey_file=/etc/ssl/servercerts/nagios-key.pem
# SSL USE CLIENT CERTS
# This options determines client certificate usage.
# Values: 0 = Don't ask for or require client certificates (default)
# 1 = Ask for client certificates
# 2 = Require client certificates
#ssl_client_certs=0
# SSL LOGGING
# This option determines which SSL messages are send to syslog. OR values
# together to specify multiple options.
# Values: 0x00 (0) = No additional logging (default)
# 0x01 (1) = Log startup SSL/TLS parameters
# 0x02 (2) = Log remote IP address
# 0x04 (4) = Log SSL/TLS version of connections
# 0x08 (8) = Log which cipher is being used for the connection
# 0x10 (16) = Log if client has a certificate
# 0x20 (32) = Log details of client's certificate if it has one
# -1 or 0xff or 0x2f = All of the above
#ssl_logging=0x00
# INCLUDE CONFIG FILE
# This directive allows you to include definitions from an external config file.
#include=<somefile.cfg>
# INCLUDE CONFIG DIRECTORY
# This directive allows you to include definitions from config files (with a
# .cfg extension) in one or more directories (with recursion).
#include_dir=<somedirectory>
#include_dir=<someotherdirectory>
# COMMAND DEFINITIONS
# Command definitions that this daemon will run. Definitions
# are in the following format:
#
# command[<command_name>]=<command_line>
#
# When the daemon receives a request to return the results of <command_name>
# it will execute the command specified by the <command_line> argument.
#
# Unlike Nagios, the command line cannot contain macros - it must be
# typed exactly as it should be executed.
#
# Note: Any plugins that are used in the command lines must reside
# on the machine that this daemon is running on! The examples below
# assume that you have plugins installed in a /usr/local/nagios/libexec
# directory. Also note that you will have to modify the definitions below
# to match the argument format the plugins expect. Remember, these are
# examples only!
# The following examples use hardcoded command arguments...
command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
# The following examples allow user-supplied arguments and can
# only be used if the NRPE daemon was compiled with support for
# command arguments *AND* the dont_blame_nrpe directive in this
# config file is set to '1'. This poses a potential security risk, so
# make sure you read the SECURITY file before doing this.
#command[check_users]=/usr/lib/nagios/plugins/check_users -w $ARG1$ -c $ARG2$
#command[check_load]=/usr/lib/nagios/plugins/check_load -w $ARG1$ -c $ARG2$
#command[check_disk]=/usr/lib/nagios/plugins/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
#command[check_procs]=/usr/lib/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
# local configuration:
# if you'd prefer, you can instead place directives here
include=/etc/nagios/nrpe_local.cfg
# you can place your config snipplets into nrpe.d/
# only snipplets ending in .cfg will get included
include_dir=/etc/nagios/nrpe.d/
#############################################################################
# Sample NRPE Config File
# Written by: Ethan Galstad (nagios@nagios.org)
#
# Last Modified: 2016-05-10
#
# NOTES:
# This is a sample configuration file for the NRPE daemon. It needs to be
# located on the remote host that is running the NRPE daemon, not the host
# from which the check_nrpe client is being executed.
#############################################################################
# LOG FACILITY
# The syslog facility that should be used for logging purposes.
log_facility=daemon
# DEBUGGING OPTION
# This option determines whether or not debugging messages are logged to the
# syslog facility.
# Values: 0=debugging off, 1=debugging on
debug=0
# PID FILE
# The name of the file in which the NRPE daemon should write it's process ID
# number. The file is only written if the NRPE daemon is started by the root
# user and is running in standalone mode.
pid_file=/var/run/nagios/nrpe.pid
# PORT NUMBER
# Port number we should wait for connections on.
# NOTE: This must be a non-priviledged port (i.e. > 1024).
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
server_port=5666
# SERVER ADDRESS
# Address that nrpe should bind to in case there are more than one interface
# and you do not want nrpe to bind on all interfaces.
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
#server_address=127.0.0.1
# LISTEN QUEUE SIZE
# Listen queue size (backlog) for serving incoming connections.
# You may want to increase this value under high load.
#listen_queue_size=5
# NRPE USER
# This determines the effective user that the NRPE daemon should run as.
# You can either supply a username or a UID.
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
nrpe_user=nagios
# NRPE GROUP
# This determines the effective group that the NRPE daemon should run as.
# You can either supply a group name or a GID.
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
nrpe_group=nagios
# ALLOWED HOST ADDRESSES
# This is an optional comma-delimited list of IP address or hostnames
# that are allowed to talk to the NRPE daemon. Network addresses with a bit mask
# (i.e. 192.168.1.0/24) are also supported. Hostname wildcards are not currently
# supported.
#
# Note: The daemon only does rudimentary checking of the client's IP
# address. I would highly recommend adding entries in your /etc/hosts.allow
# file to allow only the specified host to connect to the port
# you are running this daemon on.
#
# NOTE: This option is ignored if NRPE is running under either inetd or xinetd
allowed_hosts=192.168.201.2
# COMMAND ARGUMENT PROCESSING
# This option determines whether or not the NRPE daemon will allow clients
# to specify arguments to commands that are executed. This option only works
# if the daemon was configured with the --enable-command-args configure script
# option.
#
# *** ENABLING THIS OPTION IS A SECURITY RISK! ***
# Read the SECURITY file for information on some of the security implications
# of enabling this variable.
#
# Values: 0=do not allow arguments, 1=allow command arguments
dont_blame_nrpe=1
# BASH COMMAND SUBTITUTION
# This option determines whether or not the NRPE daemon will allow clients
# to specify arguments that contain bash command substitutions of the form
# $(...). This option only works if the daemon was configured with both
# the --enable-command-args and --enable-bash-command-substitution configure
# script options.
#
# *** ENABLING THIS OPTION IS A HIGH SECURITY RISK! ***
# Read the SECURITY file for information on some of the security implications
# of enabling this variable.
#
# Values: 0=do not allow bash command substitutions,
# 1=allow bash command substitutions
allow_bash_command_substitution=0
# COMMAND PREFIX
# This option allows you to prefix all commands with a user-defined string.
# A space is automatically added between the specified prefix string and the
# command line from the command definition.
#
# *** THIS EXAMPLE MAY POSE A POTENTIAL SECURITY RISK, SO USE WITH CAUTION! ***
# Usage scenario:
# Execute restricted commmands using sudo. For this to work, you need to add
# the nagios user to your /etc/sudoers. An example entry for alllowing
# execution of the plugins from might be:
#
# nagios ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/
#
# This lets the nagios user run all commands in that directory (and only them)
# without asking for a password. If you do this, make sure you don't give
# random users write access to that directory or its contents!
# command_prefix=/usr/bin/sudo
# COMMAND TIMEOUT
# This specifies the maximum number of seconds that the NRPE daemon will
# allow plugins to finish executing before killing them off.
command_timeout=60
# CONNECTION TIMEOUT
# This specifies the maximum number of seconds that the NRPE daemon will
# wait for a connection to be established before exiting. This is sometimes
# seen where a network problem stops the SSL being established even though
# all network sessions are connected. This causes the nrpe daemons to
# accumulate, eating system resources. Do not set this too low.
connection_timeout=300
# WEAK RANDOM SEED OPTION
# This directive allows you to use SSL even if your system does not have
# a /dev/random or /dev/urandom (on purpose or because the necessary patches
# were not applied). The random number generator will be seeded from a file
# which is either a file pointed to by the environment valiable $RANDFILE
# or $HOME/.rnd. If neither exists, the pseudo random number generator will
# be initialized and a warning will be issued.
# Values: 0=only seed from /dev/[u]random, 1=also seed from weak randomness
allow_weak_random_seed=1
# SSL/TLS OPTIONS
# These directives allow you to specify how to use SSL/TLS.
# SSL VERSION
# This can be any of: SSLv2 (only use SSLv2), SSLv2+ (use any version),
# SSLv3 (only use SSLv3), SSLv3+ (use SSLv3 or above), TLSv1 (only use
# TLSv1), TLSv1+ (use TLSv1 or above), TLSv1.1 (only use TLSv1.1),
# TLSv1.1+ (use TLSv1.1 or above), TLSv1.2 (only use TLSv1.2),
# TLSv1.2+ (use TLSv1.2 or above)
# If an "or above" version is used, the best will be negotiated. So if both
# ends are able to do TLSv1.2 and use specify SSLv2, you will get TLSv1.2.
#ssl_version=SSLv2+
# SSL USE ADH
# This is for backward compatibility and is DEPRECATED. Set to 1 to enable
# ADH or 2 to require ADH. 1 is currently the default but will be changed
# in a later version.
#ssl_use_adh=1
# SSL CIPHER LIST
# This lists which ciphers can be used. For backward compatibility, this
# defaults to 'ssl_cipher_list=ALL:!MD5:@STRENGTH' in this version but
# will be changed to something like the example below in a later version of NRPE.
#ssl_cipher_list=ALL:!MD5:@STRENGTH
#ssl_cipher_list=ALL:!aNULL:!eNULL:!SSLv2:!LOW:!EXP:!RC4:!MD5:@STRENGTH
# SSL Certificate and Private Key Files
#ssl_cacert_file=/etc/ssl/servercerts/ca-cert.pem
#ssl_cert_file=/etc/ssl/servercerts/nagios-cert.pem
#ssl_privatekey_file=/etc/ssl/servercerts/nagios-key.pem
# SSL USE CLIENT CERTS
# This options determines client certificate usage.
# Values: 0 = Don't ask for or require client certificates (default)
# 1 = Ask for client certificates
# 2 = Require client certificates
#ssl_client_certs=0
# SSL LOGGING
# This option determines which SSL messages are send to syslog. OR values
# together to specify multiple options.
# Values: 0x00 (0) = No additional logging (default)
# 0x01 (1) = Log startup SSL/TLS parameters
# 0x02 (2) = Log remote IP address
# 0x04 (4) = Log SSL/TLS version of connections
# 0x08 (8) = Log which cipher is being used for the connection
# 0x10 (16) = Log if client has a certificate
# 0x20 (32) = Log details of client's certificate if it has one
# -1 or 0xff or 0x2f = All of the above
#ssl_logging=0x00
# INCLUDE CONFIG FILE
# This directive allows you to include definitions from an external config file.
#include=<somefile.cfg>
# INCLUDE CONFIG DIRECTORY
# This directive allows you to include definitions from config files (with a
# .cfg extension) in one or more directories (with recursion).
#include_dir=<somedirectory>
#include_dir=<someotherdirectory>
# COMMAND DEFINITIONS
# Command definitions that this daemon will run. Definitions
# are in the following format:
#
# command[<command_name>]=<command_line>
#
# When the daemon receives a request to return the results of <command_name>
# it will execute the command specified by the <command_line> argument.
#
# Unlike Nagios, the command line cannot contain macros - it must be
# typed exactly as it should be executed.
#
# Note: Any plugins that are used in the command lines must reside
# on the machine that this daemon is running on! The examples below
# assume that you have plugins installed in a /usr/local/nagios/libexec
# directory. Also note that you will have to modify the definitions below
# to match the argument format the plugins expect. Remember, these are
# examples only!
# The following examples use hardcoded command arguments...
command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200
# The following examples allow user-supplied arguments and can
# only be used if the NRPE daemon was compiled with support for
# command arguments *AND* the dont_blame_nrpe directive in this
# config file is set to '1'. This poses a potential security risk, so
# make sure you read the SECURITY file before doing this.
#command[check_users]=/usr/lib/nagios/plugins/check_users -w $ARG1$ -c $ARG2$
#command[check_load]=/usr/lib/nagios/plugins/check_load -w $ARG1$ -c $ARG2$
#command[check_disk]=/usr/lib/nagios/plugins/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
#command[check_procs]=/usr/lib/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
# local configuration:
# if you'd prefer, you can instead place directives here
include=/etc/nagios/nrpe_local.cfg
# you can place your config snipplets into nrpe.d/
# only snipplets ending in .cfg will get included
include_dir=/etc/nagios/nrpe.d/

View File

@@ -1,12 +1,12 @@
######################################
# Do any local nrpe configuration here
######################################
command[check_test_file_100M]=/usr/bin/sudo /usr/lib/nagios/plugins/check_file_age -w 86400 -c 1570000 -W 50000000 -C 10 -f '/home/pi/Documents/smb/test_file_100M'
command[check_test_file_200M]=/usr/bin/sudo /usr/lib/nagios/plugins/check_file_age -w 432600 -c 1570000 -W 100000000 -C 10 -f '/home/pi/Documents/smb/test_file_200M'
command[check_test_file_500M]=/usr/bin/sudo /usr/lib/nagios/plugins/check_file_age -w 432600 -c 1570000 -W 250000000 -C 10 -f '/home/pi/Documents/smb/test_file_500M'
command[check_test_file_50M]=/usr/bin/sudo /usr/lib/nagios/plugins/check_file_age -w 86400 -c 1570000 -W 40000000 -C 10 -f '/home/pi/Documents/smb/test_file_50M'
command[check_root]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
command[check_mem]=/usr/lib/nagios/plugins/check_mem.pl -u -C -w 85 -c 95
command[check_swap]=/usr/lib/nagios/plugins/check_swap -w 30% -c 10%
command[check_sipp]=/usr/lib/nagios/plugins/check_procs -C sipp -w 1:1 -c 1:1
command[check_fprobe]=/usr/lib/nagios/plugins/check_procs -C fprobe -w 1:1 -c 1:1
######################################
# Do any local nrpe configuration here
######################################
command[check_test_file_100M]=/usr/bin/sudo /usr/lib/nagios/plugins/check_file_age -w 86400 -c 1570000 -W 50000000 -C 10 -f '/home/pi/Documents/smb/test_file_100M'
command[check_test_file_200M]=/usr/bin/sudo /usr/lib/nagios/plugins/check_file_age -w 432600 -c 1570000 -W 100000000 -C 10 -f '/home/pi/Documents/smb/test_file_200M'
command[check_test_file_500M]=/usr/bin/sudo /usr/lib/nagios/plugins/check_file_age -w 432600 -c 1570000 -W 250000000 -C 10 -f '/home/pi/Documents/smb/test_file_500M'
command[check_test_file_50M]=/usr/bin/sudo /usr/lib/nagios/plugins/check_file_age -w 86400 -c 1570000 -W 40000000 -C 10 -f '/home/pi/Documents/smb/test_file_50M'
command[check_root]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /
command[check_mem]=/usr/lib/nagios/plugins/check_mem.pl -u -C -w 85 -c 95
command[check_swap]=/usr/lib/nagios/plugins/check_swap -w 30% -c 10%
command[check_sipp]=/usr/lib/nagios/plugins/check_procs -C sipp -w 1:1 -c 1:1
command[check_fprobe]=/usr/lib/nagios/plugins/check_procs -C fprobe -w 1:1 -c 1:1

76
roles/nrpe/tasks/main.yaml Executable file → Normal file
View File

@@ -1,38 +1,38 @@
---
- name: Install nrpe and plugins
become: true
apt:
name: "{{ packages }}"
vars:
packages:
- nagios-nrpe-server
- monitoring-plugins
tags: install_nrpe
- name: Copy configuration files
become: true
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: root
group: root
mode: a+x
with_items:
- { src: "{{ role_path }}/files/nrpe.cfg", dest: "/etc/nagios" }
- { src: "{{ role_path }}/files/nrpe_local.cfg", dest: "/etc/nagios" }
- { src: "{{ role_path }}/files/check_mem.pl", dest: "/usr/lib/nagios/plugins" }
tags: configure_nrpe
- name: enable nrpe
become: true
systemd:
name: nagios-nrpe-server
enabled: yes
masked: no
state: restarted
tags: enable_nrpe
- lineinfile:
path: "/etc/sudoers"
state: present
line: "nagios ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/"
validate: "/usr/sbin/visudo -cf %s"
become: true
tags: nagios_sudo
---
- name: Install nrpe and plugins
become: true
apt:
name: "{{ packages }}"
vars:
packages:
- nagios-nrpe-server
- monitoring-plugins
tags: install_nrpe
- name: Copy configuration files
become: true
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: root
group: root
mode: a+x
with_items:
- { src: "{{ role_path }}/files/nrpe.cfg", dest: "/etc/nagios" }
- { src: "{{ role_path }}/files/nrpe_local.cfg", dest: "/etc/nagios" }
- { src: "{{ role_path }}/files/check_mem.pl", dest: "/usr/lib/nagios/plugins" }
tags: configure_nrpe
- name: enable nrpe
become: true
systemd:
name: nagios-nrpe-server
enabled: yes
masked: no
state: restarted
tags: enable_nrpe
- lineinfile:
path: "/etc/sudoers"
state: present
line: "nagios ALL=(ALL) NOPASSWD: /usr/lib/nagios/plugins/"
validate: "/usr/sbin/visudo -cf %s"
become: true
tags: nagios_sudo

44
roles/pi/tasks/main.yaml Executable file → Normal file
View File

@@ -1,17 +1,27 @@
---
- name: set swapfile
become: true
lineinfile:
path: /etc/dphys-swapfile
state: present
regexp: '^CONF_SWAPSIZE'
line: 'CONF_SWAPSIZE=1024'
owner: root
group: root
mode: 0600
tags: set_swapfile
- name: restart swapfile
become: true
command: '/etc/init.d/dphys-swapfile restart'
tags: set_swapfile
---
- name: set swapfile
become: true
lineinfile:
path: /etc/dphys-swapfile
state: present
regexp: '^CONF_SWAPSIZE'
line: 'CONF_SWAPSIZE=1024'
owner: root
group: root
mode: 0600
tags: set_swapfile
- name: restart swapfile
become: true
command: '/etc/init.d/dphys-swapfile restart'
tags: set_swapfile
- lineinfile:
path: /boot/config.txt
state: present
backrefs: yes
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { regexp: '#framebuffer_width=1280', line: 'framebuffer_width=1280' }
- { regexp: '#framebuffer_height=720', line: 'framebuffer_height=1024' }
become: true

380
roles/public/tasks/main.yaml Executable file → Normal file
View File

@@ -1,190 +1,190 @@
---
- name: Install ufw packages
package:
name: ufw
state: present
become: true
- name: Allow all access from RFC1918 networks to this hosts
ufw:
rule: allow
src: '{{ item }}'
with_items:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
become: true
- name: Allow all access from any Comcast IP Space
become: true
ufw:
rule: allow
src: '{{ item }} '
with_items:
- 72.94.169.223/32
- 100.96.0.0/11
- 103.72.193.0/24
- 107.0.0.0/14
- 107.4.0.0/15
- 108.171.224.0/20
- 147.191.0.0/16
- 162.148.0.0/14
- 162.17.0.0/16
- 165.137.0.0/16
- 169.152.0.0/16
- 169.152.0.0/16
- 173.160.0.0/13
- 173.8.0.0/13
- 174.160.0.0/11
- 174.48.0.0/12
- 184.108.0.0/14
- 184.112.0.0/12
- 193.57.148.0/22
- 198.0.0.0/16
- 198.137.252.0/23
- 198.178.8.0/21
- 207.223.0.0/20
- 208.110.192.0/19
- 208.39.128.0/18
- 209.23.192.0/18
- 216.45.128.0/17
- 23.24.0.0/15
- 23.30.0.0/15
- 23.68.0.0/14
- 232.128.0.0/13
- 232.232.0.0/14
- 232.36.0.0/14
- 232.40.0.0/14
- 232.44.0.0/14
- 232.48.0.0/14
- 232.52.0.0/14
- 232.56.0.0/14
- 232.64.0.0/14
- 232.80.0.0/14
- 232.96.0.0/14
- 239.12.0.0/14
- 239.16.0.0/14
- 239.20.0.0/14
- 239.24.0.0/14
- 239.28.0.0/14
- 239.32.0.0/14
- 24.0.0.0/12
- 24.104.0.0/17
- 24.104.128.0/19
- 24.118.0.0/16
- 24.124.128.0/17
- 24.125.0.0/16
- 24.126.0.0/15
- 24.128.0.0/16
- 24.129.0.0/17
- 24.130.0.0/15
- 24.147.0.0/16
- 24.149.128.0/17
- 24.153.64.0/19
- 24.153.72.0/21
- 24.16.0.0/13
- 24.218.0.0/16
- 24.245.0.0/18
- 24.30.0.0/17
- 24.34.0.0/16
- 24.40.0.0/18
- 24.40.64.0/20
- 24.60.0.0/14
- 24.91.0.0/16
- 24.98.0.0/15
- 3.81.241.149
- 50.128.0.0/9
- 50.73.0.0/16
- 50.76.0.0/14
- 64.139.64.0/19
- 64.235.160.0/19
- 64.56.32.0/19
- 64.78.64.0/18
- 65.34.128.0/17
- 65.96.0.0/16
- 66.176.0.0/15
- 66.208.192.0/18
- 66.229.0.0/16
- 66.240.0.0/18
- 66.30.0.0/15
- 66.41.0.0/16
- 66.56.0.0/18
- 67.160.0.0/11
- 67.178.0.0/17
- 67.178.128.0/17
- 67.179.0.0/16
- 68.32.0.0/11
- 68.80.0.0/13
- 68.85.0.0/20
- 68.85.128.0/17
- 68.85.16.0/20
- 68.85.32.0/19
- 68.85.64.0/18
- 68.86.0.0/18
- 68.86.128.0/17
- 68.86.64.0/18
- 68.87.0.0/20
- 68.87.128.0/18
- 68.87.16.0/20
- 68.87.192.0/19
- 68.87.224.0/20
- 68.87.240.0/20
- 68.87.32.0/19
- 68.87.64.0/18
- 69.136.0.0/13
- 69.139.128.0/20
- 69.139.144.0/20
- 69.139.160.0/19
- 69.139.192.0/18
- 69.180.0.0/15
- 69.240.0.0/12
- 70.88.0.0/14
- 71.192.0.0/12
- 71.224.0.0/12
- 71.24.0.0/14
- 71.56.0.0/13
- 72.55.0.0/17
- 73.0.0.0/8
- 74.144.0.0/12
- 74.16.0.0/12
- 74.81.128.0/19
- 74.92.0.0/14
- 75.144.0.0/13
- 75.64.0.0/13
- 75.72.0.0/15
- 75.74.0.0/16
- 75.75.0.0/17
- 75.75.128.0/18
- 75.75.72.0/21
- 76.128.0.0/11
- 76.16.0.0/12
- 76.96.0.0/11
- 96.100.0.0/14
- 96.106.0.0/15
- 96.108.0.0/17
- 96.108.128.0/18
- 96.108.192.0/19
- 96.108.224.0/19
- 96.109.0.0/16
- 96.110.0.0/16
- 96.111.0.0/16
- 96.112.0.0/13
- 96.120.0.0/14
- 96.124.0.0/16
- 96.128.0.0/10
- 96.192.0.0/11
- 96.64.0.0/11
- 96.96.0.0/12
- 98.192.0.0/10
- 98.205.0.0/16
- 98.241.0.0/16
- 98.32.0.0/11
- name: Allow DHCP
ufw:
rule: allow
to_port: 67
become: true
tags: ufw_dhcp
- name: Enable UFW
ufw:
state: enabled
policy: deny
become: true
---
- name: Install ufw packages
package:
name: ufw
state: present
become: true
- name: Allow all access from RFC1918 networks to this hosts
ufw:
rule: allow
src: '{{ item }}'
with_items:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
become: true
- name: Allow all access from any Comcast IP Space
become: true
ufw:
rule: allow
src: '{{ item }} '
with_items:
- 72.94.169.223/32
- 100.96.0.0/11
- 103.72.193.0/24
- 107.0.0.0/14
- 107.4.0.0/15
- 108.171.224.0/20
- 147.191.0.0/16
- 162.148.0.0/14
- 162.17.0.0/16
- 165.137.0.0/16
- 169.152.0.0/16
- 169.152.0.0/16
- 173.160.0.0/13
- 173.8.0.0/13
- 174.160.0.0/11
- 174.48.0.0/12
- 184.108.0.0/14
- 184.112.0.0/12
- 193.57.148.0/22
- 198.0.0.0/16
- 198.137.252.0/23
- 198.178.8.0/21
- 207.223.0.0/20
- 208.110.192.0/19
- 208.39.128.0/18
- 209.23.192.0/18
- 216.45.128.0/17
- 23.24.0.0/15
- 23.30.0.0/15
- 23.68.0.0/14
- 232.128.0.0/13
- 232.232.0.0/14
- 232.36.0.0/14
- 232.40.0.0/14
- 232.44.0.0/14
- 232.48.0.0/14
- 232.52.0.0/14
- 232.56.0.0/14
- 232.64.0.0/14
- 232.80.0.0/14
- 232.96.0.0/14
- 239.12.0.0/14
- 239.16.0.0/14
- 239.20.0.0/14
- 239.24.0.0/14
- 239.28.0.0/14
- 239.32.0.0/14
- 24.0.0.0/12
- 24.104.0.0/17
- 24.104.128.0/19
- 24.118.0.0/16
- 24.124.128.0/17
- 24.125.0.0/16
- 24.126.0.0/15
- 24.128.0.0/16
- 24.129.0.0/17
- 24.130.0.0/15
- 24.147.0.0/16
- 24.149.128.0/17
- 24.153.64.0/19
- 24.153.72.0/21
- 24.16.0.0/13
- 24.218.0.0/16
- 24.245.0.0/18
- 24.30.0.0/17
- 24.34.0.0/16
- 24.40.0.0/18
- 24.40.64.0/20
- 24.60.0.0/14
- 24.91.0.0/16
- 24.98.0.0/15
- 3.81.241.149
- 50.128.0.0/9
- 50.73.0.0/16
- 50.76.0.0/14
- 64.139.64.0/19
- 64.235.160.0/19
- 64.56.32.0/19
- 64.78.64.0/18
- 65.34.128.0/17
- 65.96.0.0/16
- 66.176.0.0/15
- 66.208.192.0/18
- 66.229.0.0/16
- 66.240.0.0/18
- 66.30.0.0/15
- 66.41.0.0/16
- 66.56.0.0/18
- 67.160.0.0/11
- 67.178.0.0/17
- 67.178.128.0/17
- 67.179.0.0/16
- 68.32.0.0/11
- 68.80.0.0/13
- 68.85.0.0/20
- 68.85.128.0/17
- 68.85.16.0/20
- 68.85.32.0/19
- 68.85.64.0/18
- 68.86.0.0/18
- 68.86.128.0/17
- 68.86.64.0/18
- 68.87.0.0/20
- 68.87.128.0/18
- 68.87.16.0/20
- 68.87.192.0/19
- 68.87.224.0/20
- 68.87.240.0/20
- 68.87.32.0/19
- 68.87.64.0/18
- 69.136.0.0/13
- 69.139.128.0/20
- 69.139.144.0/20
- 69.139.160.0/19
- 69.139.192.0/18
- 69.180.0.0/15
- 69.240.0.0/12
- 70.88.0.0/14
- 71.192.0.0/12
- 71.224.0.0/12
- 71.24.0.0/14
- 71.56.0.0/13
- 72.55.0.0/17
- 73.0.0.0/8
- 74.144.0.0/12
- 74.16.0.0/12
- 74.81.128.0/19
- 74.92.0.0/14
- 75.144.0.0/13
- 75.64.0.0/13
- 75.72.0.0/15
- 75.74.0.0/16
- 75.75.0.0/17
- 75.75.128.0/18
- 75.75.72.0/21
- 76.128.0.0/11
- 76.16.0.0/12
- 76.96.0.0/11
- 96.100.0.0/14
- 96.106.0.0/15
- 96.108.0.0/17
- 96.108.128.0/18
- 96.108.192.0/19
- 96.108.224.0/19
- 96.109.0.0/16
- 96.110.0.0/16
- 96.111.0.0/16
- 96.112.0.0/13
- 96.120.0.0/14
- 96.124.0.0/16
- 96.128.0.0/10
- 96.192.0.0/11
- 96.64.0.0/11
- 96.96.0.0/12
- 98.192.0.0/10
- 98.205.0.0/16
- 98.241.0.0/16
- 98.32.0.0/11
- name: Allow DHCP
ufw:
rule: allow
to_port: 67
become: true
tags: ufw_dhcp
- name: Enable UFW
ufw:
state: enabled
policy: deny
become: true

0
roles/salesforce/files/salesforce.sh Executable file → Normal file
View File

File diff suppressed because it is too large Load Diff

40
roles/salesforce/tasks/main.yaml Executable file → Normal file
View File

@@ -1,20 +1,20 @@
---
- name: copy salesforce script
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: pi
group: pi
mode: a+x
with_items:
- { src: "{{ role_path }}/files/salesforce.sh", dest: "/home/pi/scripts/salesforce.sh" }
- { src: "{{ role_path }}/files/salesforce_url.list", dest: "/home/pi/Documents/salesforce_url.list" }
tags: salesforcetraff_script
- name: enable cron job for salesforce traffic
cron:
name: "salesforcetraff"
minute: "*/5"
hour: "7-18"
weekday: "1-5"
job: "/home/pi/scripts/salesforce.sh"
tags: salesforcetraff_cron
---
- name: copy salesforce script
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: pi
group: pi
mode: a+x
with_items:
- { src: "{{ role_path }}/files/salesforce.sh", dest: "/home/pi/scripts/salesforce.sh" }
- { src: "{{ role_path }}/files/salesforce_url.list", dest: "/home/pi/Documents/salesforce_url.list" }
tags: salesforcetraff_script
- name: enable cron job for salesforce traffic
cron:
name: "salesforcetraff"
minute: "*/5"
hour: "7-18"
weekday: "1-5"
job: "/home/pi/scripts/salesforce.sh"
tags: salesforcetraff_cron

View File

@@ -1,54 +1,54 @@
SAMBA Server Installation on Ubuntu Server using Ansible
--------
There's a blog post that I wrote to go along with this. [Check it out!]
This role is helpful to install SAMBA server on Ubuntu server 14.04 LTS.
[SAMBA Installation Tutorial] - This step by step tutorial explains the installation and configuration of a SAMBA server on Ubuntu server.
### To use this Role:
Edit the `site.yml` file, mentioned this role:
```yaml
---
- hosts: server
become: yes
gather_facts: yes
roles:
- samba
```
After that edit the `defaults/main.yml` file:
> Change the username(s) and their smbpassword, but these user(s) must exist on the target system.
> Also change the other values as per your requirement. These are self explanatory.
```yaml
---
ubuntu_samba_packages:
- samba
- samba-common
- python-glade2
- system-config-samba
workgroup: WORKGROUP
public_share_name: public
public_share_path: /samba/public
private_share_name: private
private_share_path: /samba/private
samba_group_name: smbgrp
samba_users:
- name: 'arbab'
smbpasswd: 'pass123'
- name: 'hussain'
smbpasswd: 'password'
```
Then run this command:
```
ansible-playbook -i hosts -u arbab site.yml
```
**Note:** Please don't forget to change `arbab` with your username
[SAMBA Installation Tutorial]:https://rbgeek.wordpress.com/2012/04/25/how-to-install-samba-server-on-ubuntu-12-04/
[Check it out!]:https://rbgeek.wordpress.com/2015/02/23/installing-the-samba-server-on-ubuntu-using-ansible/
SAMBA Server Installation on Ubuntu Server using Ansible
--------
There's a blog post that I wrote to go along with this. [Check it out!]
This role is helpful to install SAMBA server on Ubuntu server 14.04 LTS.
[SAMBA Installation Tutorial] - This step by step tutorial explains the installation and configuration of a SAMBA server on Ubuntu server.
### To use this Role:
Edit the `site.yml` file, mentioned this role:
```yaml
---
- hosts: server
become: yes
gather_facts: yes
roles:
- samba
```
After that edit the `defaults/main.yml` file:
> Change the username(s) and their smbpassword, but these user(s) must exist on the target system.
> Also change the other values as per your requirement. These are self explanatory.
```yaml
---
ubuntu_samba_packages:
- samba
- samba-common
- python-glade2
- system-config-samba
workgroup: WORKGROUP
public_share_name: public
public_share_path: /samba/public
private_share_name: private
private_share_path: /samba/private
samba_group_name: smbgrp
samba_users:
- name: 'arbab'
smbpasswd: 'pass123'
- name: 'hussain'
smbpasswd: 'password'
```
Then run this command:
```
ansible-playbook -i hosts -u arbab site.yml
```
**Note:** Please don't forget to change `arbab` with your username
[SAMBA Installation Tutorial]:https://rbgeek.wordpress.com/2012/04/25/how-to-install-samba-server-on-ubuntu-12-04/
[Check it out!]:https://rbgeek.wordpress.com/2015/02/23/installing-the-samba-server-on-ubuntu-using-ansible/

View File

@@ -1,17 +1,17 @@
---
ubuntu_samba_packages:
- samba
- samba-common
- python-glade2
- system-config-samba
workgroup: DEMO
public_share_name: share
public_share_path: /media/share
private_share_name: private
private_share_path: /media/private
samba_group_name: smbgrp
samba_users:
- name: 'demo'
smbpasswd: 'Demo123'
- name: 'pi'
smbpasswd: 'pipasswd'
---
ubuntu_samba_packages:
- samba
- samba-common
- python-glade2
# - system-config-samba
workgroup: DEMO
public_share_name: share
public_share_path: /media/share
private_share_name: private
private_share_path: /media/private
samba_group_name: smbgrp
samba_users:
- name: 'demo'
smbpasswd: 'Demo123'
- name: 'pi'
smbpasswd: 'pipasswd'

View File

@@ -1,8 +1,9 @@
---
- name: Restart Samba
service:
name: smbd.service
state: restarted
- name: Generate Samba Files
become: yes
shell: /home/pi/scripts/genfiles.sh
---
- name: Restart Samba
systemd:
name: smbd.service
state: restarted
enabled: yes
- name: Generate Samba Files
become: yes
shell: /home/pi/scripts/genfiles.sh

View File

@@ -1,74 +1,72 @@
---
- name: Install the Samba and additional packages
apt:
name: "{{ ubuntu_samba_packages }}"
state: present
update_cache: yes
become: yes
- name: Copy the Customize smb.conf file
become: yes
template:
src: etc_samba_smb.conf.j2
dest: /etc/samba/smb.conf
backup: yes
notify:
- Restart Samba
- name: Create Samba users restricted group
group:
name: "{{ samba_group_name }}"
state: present
become: yes
- name: Add the User(s) to Samba group
user:
name: "{{ item.name }}"
groups: "{{ samba_group_name }}"
append: yes
become: yes
with_items: "{{ samba_users }}"
- name: Create Samba Password for User(s)
shell: "(echo {{ item.smbpasswd }}; echo {{ item.smbpasswd }}) | smbpasswd -s -a {{ item.name }}"
with_items: "{{ samba_users }}"
become: yes
- name: "Check that {{ public_share_path }} exist"
stat:
path: "{{ public_share_path }}"
register: public_dir_exists
- name: "Create {{ public_share_path }} directory"
become: yes
file:
state: directory
path: "{{ public_share_path }}"
owner: nobody
group: nogroup
mode: 0755
recurse: yes
when: public_dir_exists.stat.exists == False
- name: "Check that {{ private_share_path }} exist"
stat:
path: "{{ private_share_path }}"
register: private_dir_exists
- name: "Create {{ private_share_path }} directory"
become: yes
file:
state: directory
path: "{{ private_share_path }}"
owner: root
group: "{{ samba_group_name }}"
mode: 1770
when: private_dir_exists.stat.exists == False
- name: copy genfiles script
copy:
src: "{{ role_path }}/files/genfiles.sh"
dest: /home/pi/scripts/genfiles.sh
owner: pi
group: pi
mode: a+x
tags: samba_genfiles
notify:
- Generate Samba Files
---
- name: Install the Samba and additional packages
apt:
name: "{{ ubuntu_samba_packages }}"
state: present
update_cache: yes
become: yes
- name: Copy the Customize smb.conf file
become: yes
template:
src: etc_samba_smb.conf.j2
dest: /etc/samba/smb.conf
backup: yes
# notify: Restart Samba
- name: Create Samba users restricted group
group:
name: "{{ samba_group_name }}"
state: present
become: yes
- name: Add the User(s) to Samba group
user:
name: "{{ item.name }}"
groups: "{{ samba_group_name }}"
append: yes
become: yes
with_items: "{{ samba_users }}"
- name: Create Samba Password for User(s)
shell: "(echo {{ item.smbpasswd }}; echo {{ item.smbpasswd }}) | smbpasswd -s -a {{ item.name }}"
with_items: "{{ samba_users }}"
become: yes
- name: "Check that {{ public_share_path }} exist"
stat:
path: "{{ public_share_path }}"
register: public_dir_exists
- name: "Create {{ public_share_path }} directory"
become: yes
file:
state: directory
path: "{{ public_share_path }}"
owner: nobody
group: nogroup
mode: 0755
recurse: yes
when: public_dir_exists.stat.exists == False
- name: "Check that {{ private_share_path }} exist"
stat:
path: "{{ private_share_path }}"
register: private_dir_exists
- name: "Create {{ private_share_path }} directory"
become: yes
file:
state: directory
path: "{{ private_share_path }}"
owner: root
group: "{{ samba_group_name }}"
mode: 1770
when: private_dir_exists.stat.exists == False
- name: copy genfiles script
copy:
src: "{{ role_path }}/files/genfiles.sh"
dest: /home/pi/scripts/genfiles.sh
owner: pi
group: pi
mode: a+x
tags: samba_genfiles
notify: Generate Samba Files

View File

@@ -1,28 +1,28 @@
#======================= Global Settings =====================================
#{{ ansible_managed }}
[global]
workgroup = {{ workgroup }}
server string = Samba Server %v
netbios name = ubuntu
security = user
map to guest = bad user
dns proxy = no
#============================ Share Definitions ==============================
#### Public Share ####
[{{ public_share_name }}]
path = {{ public_share_path }}
browsable =yes
writable = yes
guest ok = yes
read only = no
#### Private Share ####
[{{ private_share_name }}]
path = {{ private_share_path }}
valid users = @{{ samba_group_name }}
guest ok = no
writable = yes
browsable = yes
create mask = 0700
directory mask = 0700
#======================= Global Settings =====================================
#{{ ansible_managed }}
[global]
workgroup = {{ workgroup }}
server string = Samba Server %v
netbios name = ubuntu
security = user
map to guest = bad user
dns proxy = no
#============================ Share Definitions ==============================
#### Public Share ####
[{{ public_share_name }}]
path = {{ public_share_path }}
browsable =yes
writable = yes
guest ok = yes
read only = no
#### Private Share ####
[{{ private_share_name }}]
path = {{ private_share_path }}
valid users = @{{ samba_group_name }}
guest ok = no
writable = yes
browsable = yes
create mask = 0700
directory mask = 0700

40
roles/sipclient/tasks/main.yaml Executable file → Normal file
View File

@@ -1,20 +1,20 @@
---
- name: enable sip client
become: true
cron:
name: "sip client"
minute: "*/30"
hour: "8-18"
weekday: "1-5"
job: "/usr/bin/perl -e 'sleep int rand 1800' && /home/pi/sipp/startclient.sh"
user: root
tags: sipclient_cron
- name: stop sip calling after hours
become: true
cron:
name: "stop sip client"
hour: "17"
weekday: "1-5"
job: "/usr/bin/perl -e 'sleep int rand 1800' && /home/pi/sipp/stopclient.sh"
user: root
tags: sipclient_stop
---
- name: enable sip client
become: true
cron:
name: "sip client"
minute: "*/30"
hour: "8-18"
weekday: "1-5"
job: "/usr/bin/perl -e 'sleep int rand 1800' && /home/pi/sipp/startclient.sh"
user: root
tags: sipclient_cron
- name: stop sip calling after hours
become: true
cron:
name: "stop sip client"
hour: "17"
weekday: "1-5"
job: "/usr/bin/perl -e 'sleep int rand 1800' && /home/pi/sipp/stopclient.sh"
user: root
tags: sipclient_stop

0
roles/sipp/files/startclient.sh Executable file → Normal file
View File

0
roles/sipp/files/startserver.sh Executable file → Normal file
View File

118
roles/sipp/tasks/main.yaml Executable file → Normal file
View File

@@ -1,59 +1,59 @@
---
- name: download sipp source
get_url:
url: "https://github.com/SIPp/sipp/releases/download/v3.5.2/sipp-3.5.2.tar.gz"
dest: "/home/pi/sipp-3.5.2.tar.gz"
register: sipp_source
tags: sipp
- name: Unpacking SIPP
unarchive:
copy: no
dest: /home/pi/
src: "/home/pi/sipp-3.5.2.tar.gz"
when: sipp_source.changed
register: sipp_source_unpack
tags: sipp
- name: move sipp directory
command: 'mv sipp-3.5.2 sipp'
when: sipp_source_unpack is changed
register: sipp_move_directory
tags: sipp
- name: configure sipp
command: "./configure --with-openssl --with-pcap --with-sctp"
args:
chdir: "/home/pi/sipp"
when: sipp_move_directory is changed
tags: sipp
register: sipp_configure
- name: build sipp
shell: make
when: sipp_configure is changed
args:
chdir: "/home/pi/sipp"
tags: sipp
- name: copy scripts
when: sipp_move_directory is changed
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: pi
group: pi
mode: a+x
with_items:
- { src: "{{ role_path }}/files/startserver.sh", dest: "/home/pi/sipp/startserver.sh" }
- { src: "{{ role_path }}/files/startclient.sh", dest: "/home/pi/sipp/startclient.sh" }
- { src: "{{ role_path }}/files/stopclient.sh", dest: "/home/pi/sipp/stopclient.sh" }
tags: sipp
- name: copy scripts2
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: pi
group: pi
mode: a+x
with_items:
- { src: "{{ role_path }}/files/startserver.sh", dest: "/home/pi/sipp/startserver.sh" }
- { src: "{{ role_path }}/files/startclient.sh", dest: "/home/pi/sipp/startclient.sh" }
- { src: "{{ role_path }}/files/stopclient.sh", dest: "/home/pi/sipp/stopclient.sh" }
tags: sipp_scripts
---
- name: download sipp source
get_url:
url: "https://github.com/SIPp/sipp/releases/download/v3.5.2/sipp-3.5.2.tar.gz"
dest: "/home/pi/sipp-3.5.2.tar.gz"
register: sipp_source
tags: sipp
- name: Unpacking SIPP
unarchive:
copy: no
dest: /home/pi/
src: "/home/pi/sipp-3.5.2.tar.gz"
when: sipp_source.changed
register: sipp_source_unpack
tags: sipp
- name: move sipp directory
command: 'mv sipp-3.5.2 sipp'
when: sipp_source_unpack is changed
register: sipp_move_directory
tags: sipp
- name: configure sipp
command: "./configure --with-openssl --with-pcap --with-sctp"
args:
chdir: "/home/pi/sipp"
when: sipp_move_directory is changed
tags: sipp
register: sipp_configure
- name: build sipp
shell: make
when: sipp_configure is changed
args:
chdir: "/home/pi/sipp"
tags: sipp
- name: copy scripts
when: sipp_move_directory is changed
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: pi
group: pi
mode: a+x
with_items:
- { src: "{{ role_path }}/files/startserver.sh", dest: "/home/pi/sipp/startserver.sh" }
- { src: "{{ role_path }}/files/startclient.sh", dest: "/home/pi/sipp/startclient.sh" }
- { src: "{{ role_path }}/files/stopclient.sh", dest: "/home/pi/sipp/stopclient.sh" }
tags: sipp
- name: copy scripts2
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: pi
group: pi
mode: a+x
with_items:
- { src: "{{ role_path }}/files/startserver.sh", dest: "/home/pi/sipp/startserver.sh" }
- { src: "{{ role_path }}/files/startclient.sh", dest: "/home/pi/sipp/startclient.sh" }
- { src: "{{ role_path }}/files/stopclient.sh", dest: "/home/pi/sipp/stopclient.sh" }
tags: sipp_scripts

18
roles/sipserver/tasks/main.yaml Executable file → Normal file
View File

@@ -1,9 +1,9 @@
---
- name: enable cron job for sip server
become: true
cron:
name: "sipserver"
minute: "*/30"
user: root
job: "/home/pi/sipp/startserver.sh"
tags: sipserver_cron
---
- name: enable cron job for sip server
become: true
cron:
name: "sipserver"
minute: "*/30"
user: root
job: "/home/pi/sipp/startserver.sh"
tags: sipserver_cron

View File

@@ -1,4 +1,4 @@
username=demo
password=Demo123
domain=DEMO
username=demo
password=Demo123
domain=DEMO

2
roles/smbclient/files/smb-session.sh Executable file → Normal file
View File

@@ -13,6 +13,6 @@ if pgrep -f test_file >/dev/null
then
exit 0
else
smbclient //192.168.198.2/share -c "get $file" -A ~/.credentials
smbclient //192.168.88.230/share -c "get $file" -A ~/.credentials
fi

48
roles/smbclient/tasks/main.yaml Executable file → Normal file
View File

@@ -1,24 +1,24 @@
---
- name: enable cron job for smb traffic
cron:
name: "smbtraff"
minute: "*/60"
hour: "7-18"
weekday: "1-5"
job: "/usr/bin/perl -e 'sleep int rand 3500' && /home/pi/scripts/smb-session.sh"
tags: smbtraff_cron
- name: copy smb-session.sh to scripts directory
copy:
src: "{{ role_path }}/files/smb-session.sh"
dest: /home/pi/scripts/smb-session.sh
owner: pi
group: pi
mode: a+x
tags: smbtraff_script
- name: copy credentials to user directory
copy:
src: "{{ role_path }}/files/.credentials"
dest: /home/pi
owner: pi
group: pi
tags: smbtraff_credentials
---
- name: enable cron job for smb traffic
cron:
name: "smbtraff"
minute: "*/60"
hour: "7-18"
weekday: "1-5"
job: "/usr/bin/perl -e 'sleep int rand 3500' && /home/pi/scripts/smb-session.sh"
tags: smbtraff_cron
- name: copy smb-session.sh to scripts directory
copy:
src: "{{ role_path }}/files/smb-session.sh"
dest: /home/pi/scripts/smb-session.sh
owner: pi
group: pi
mode: a+x
tags: smbtraff_script
- name: copy credentials to user directory
copy:
src: "{{ role_path }}/files/.credentials"
dest: /home/pi
owner: pi
group: pi
tags: smbtraff_credentials

64
roles/snmpd/tasks/main.yaml Executable file → Normal file
View File

@@ -1,32 +1,32 @@
---
- name: Install snmpd Package
become: yes
apt:
name: ['snmpd']
state: present
update_cache: true
tags: install_snmpd
- lineinfile:
path: /etc/snmp/snmpd.conf
state: present
backrefs: yes
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { regexp: '^\s+rocommunity\s+public\s+default\s+-V\s+systemonly', line: ' rocommunity {{ rocommunity }}' }
- { regexp: '^agentAddress\s+udp:127.0.0.1:161', line: 'agentAddress udp:161' }
tags: configure_snmpd
become: true
- name: enable snmpd service and ensure it is not masked
systemd:
name: snmpd
enabled: yes
masked: no
state: restarted
tags: enable_snmpd
become: true
- name: set timezone
become: true
timezone:
name: America/New_York
tags: set_timezone
---
- name: Install snmpd Package
become: yes
apt:
name: ['snmpd']
state: present
update_cache: true
tags: install_snmpd
- lineinfile:
path: /etc/snmp/snmpd.conf
state: present
backrefs: yes
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { regexp: '^\s+rocommunity\s+public\s+default\s+-V\s+systemonly', line: ' rocommunity {{ rocommunity }}' }
- { regexp: '^agentAddress\s+udp:127.0.0.1:161', line: 'agentAddress udp:161' }
tags: configure_snmpd
become: true
- name: enable snmpd service and ensure it is not masked
systemd:
name: snmpd
enabled: yes
masked: no
state: restarted
tags: enable_snmpd
become: true
- name: set timezone
become: true
timezone:
name: America/New_York
tags: set_timezone

View File

@@ -1,4 +1,4 @@
Authentication=VncAuth
Encryption=PreferOn
Password=12d2f5a0e446b80ad72a2ec6a3688ee308f543f59d7bf06f
Authentication=VncAuth
Encryption=PreferOn
Password=12d2f5a0e446b80ad72a2ec6a3688ee308f543f59d7bf06f

40
roles/vnc/tasks/main.yaml Executable file → Normal file
View File

@@ -1,17 +1,23 @@
---
- name: enable vnc service and ensure it is not masked
become: true
systemd:
name: vncserver-x11-serviced.service
enabled: yes
masked: no
state: restarted
tags: enable_vnc
- name: copy vnc configuration with password
become: true
copy:
src: "{{ role_path }}/files/vncserver-x11"
dest: /root/.vnc/config.d/vncserver-x11
owner: root
group: root
tags: vnc_config
---
- name: enable vnc service and ensure it is not masked
become: true
systemd:
name: vncserver-x11-serviced.service
enabled: yes
masked: no
state: restarted
tags: enable_vnc
- name: copy vnc configuration with password
become: true
copy:
src: "{{ role_path }}/files/vncserver-x11"
dest: /root/.vnc/config.d/vncserver-x11
owner: root
group: root
tags: vnc_config
- name: set lxde in .xsession
lineinfile:
path: /home/pi/.xsession
line: lxsession -s Lubuntu -e LXDE
create: yes

0
roles/webclient/files/cadaver-webdav-clean.sh Executable file → Normal file
View File

0
roles/webclient/files/cadaver-webdav.sh Executable file → Normal file
View File

0
roles/webclient/files/webdav-session.sh Executable file → Normal file
View File

View File

@@ -1,7 +1,7 @@
interface=wlan0
dhcp-range=10.250.250.2,10.250.250.6,255.255.255.248,24h
listen-address=10.250.250.1
bind-interfaces
server=8.8.8.8
bogus-priv
interface=wlan0
dhcp-range=10.250.250.2,10.250.250.6,255.255.255.248,24h
listen-address=10.250.250.1
bind-interfaces
server=8.8.8.8
bogus-priv
domain=demo.dsfinancial.com

View File

@@ -1,15 +1,15 @@
interface=wlan0
driver=nl80211
hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
ignore_broadcast_ssid=0
wpa=2
auth_algs=1
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
ssid=PHLIPAMT
wpa_passphrase=dsfinisdemo
interface=wlan0
driver=nl80211
hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
ignore_broadcast_ssid=0
wpa=2
auth_algs=1
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
ssid=PHLIPAMT
wpa_passphrase=dsfinisdemo

View File

@@ -1,18 +1,18 @@
# Generated by iptables-save v1.6.0 on Thu Mar 14 09:59:15 2019
*filter
:INPUT ACCEPT [7056:1877085]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [6972:1880076]
-A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -j ACCEPT
COMMIT
# Completed on Thu Mar 14 09:59:15 2019
# Generated by iptables-save v1.6.0 on Thu Mar 14 09:59:15 2019
*nat
:PREROUTING ACCEPT [15:3832]
:INPUT ACCEPT [15:3832]
:OUTPUT ACCEPT [110:30472]
:POSTROUTING ACCEPT [106:29680]
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
# Completed on Thu Mar 14 09:59:15 2019
# Generated by iptables-save v1.6.0 on Thu Mar 14 09:59:15 2019
*filter
:INPUT ACCEPT [7056:1877085]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [6972:1880076]
-A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -i wlan0 -o eth0 -j ACCEPT
COMMIT
# Completed on Thu Mar 14 09:59:15 2019
# Generated by iptables-save v1.6.0 on Thu Mar 14 09:59:15 2019
*nat
:PREROUTING ACCEPT [15:3832]
:INPUT ACCEPT [15:3832]
:OUTPUT ACCEPT [110:30472]
:POSTROUTING ACCEPT [106:29680]
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
# Completed on Thu Mar 14 09:59:15 2019

216
roles/wifi/tasks/main.yaml Executable file → Normal file
View File

@@ -1,108 +1,108 @@
---
- name: Remove wpasupplicant package
become: yes
apt:
name: ['wpasupplicant']
state: absent
purge: true
tags: wireless_ap
- name: configure wlan0
become: true
blockinfile:
path: /etc/dhcpcd.conf
block: |
interface wlan0
static ip_address=10.250.250.1/29
nohook wpa_supplicant
tags: wireless_ap
- name: install hostapd
become: true
apt:
name: ['hostapd']
state: present
tags: wireless_ap
- name: configure hostapd
become: true
template:
src: "{{ role_path }}/templates/hostapd.conf.j2"
dest: "/etc/hostapd/hostapd.conf"
owner: root
group: root
backup: yes
tags: wireless_ap
- name: configure hostapd startup
become: true
tags: wireless_ap
lineinfile:
state: present
path: "{{ item.path }}"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { path: "/etc/init.d/hostapd", regexp: "^DAEMON_CONF=", line: "DAEMON_CONF=/etc/hostapd/hostapd.conf" }
- { path: "/etc/default/hostapd", regexp: "^#DAEMON_CONF=", line: "DAEMON_CONF=\"/etc/hostapd/hostapd.conf\"" }
- name: enable hostapd
become: true
systemd:
name: hostapd
enabled: yes
masked: no
state: restarted
tags: wireless_ap
- name: install dnsmasq
become: true
apt:
name: ['dnsmasq']
state: present
tags: wireless_ap
- name: configure dnsmasq
become: true
copy:
src: "{{ role_path }}/files/dnsmasq.conf"
dest: "/etc/dnsmasq.conf"
backup: yes
owner: root
group: root
tags: wireless_ap
- name: enable dnsmasq
become: true
systemd:
name: dnsmasq
enabled: yes
masked: no
state: restarted
tags: wireless_ap
- name: enable ipv4.forwarding
become: true
sysctl:
name: net.ipv4.ip_forward
value: 1
sysctl_set: yes
state: present
reload: yes
tags: wireless_ap
- name: copy fw config
become: true
copy:
src: "{{ role_path }}/files/iptables.ipv4.nat"
dest: "/etc/iptables.ipv4.nat"
backup: yes
owner: root
group: root
tags: wireless_ap
- name: iptables-restore to rc.local
lineinfile:
path: "/etc/rc.local"
state: present
insertbefore: "exit 0"
line: "iptables-restore < /etc/iptables.ipv4.nat"
become: true
tags: wireless_ap
- name: restart dhcpcd
become: true
systemd:
name: dhcpcd
enabled: yes
masked: no
state: restarted
tags: wireless_ap
---
- name: Remove wpasupplicant package
become: yes
apt:
name: ['wpasupplicant']
state: absent
purge: true
tags: wireless_ap
- name: configure wlan0
become: true
blockinfile:
path: /etc/dhcpcd.conf
block: |
interface wlan0
static ip_address=10.250.250.1/29
nohook wpa_supplicant
tags: wireless_ap
- name: install hostapd
become: true
apt:
name: ['hostapd']
state: present
tags: wireless_ap
- name: configure hostapd
become: true
template:
src: "{{ role_path }}/templates/hostapd.conf.j2"
dest: "/etc/hostapd/hostapd.conf"
owner: root
group: root
backup: yes
tags: wireless_ap
- name: configure hostapd startup
become: true
tags: wireless_ap
lineinfile:
state: present
path: "{{ item.path }}"
regexp: "{{ item.regexp }}"
line: "{{ item.line }}"
with_items:
- { path: "/etc/init.d/hostapd", regexp: "^DAEMON_CONF=", line: "DAEMON_CONF=/etc/hostapd/hostapd.conf" }
- { path: "/etc/default/hostapd", regexp: "^#DAEMON_CONF=", line: "DAEMON_CONF=\"/etc/hostapd/hostapd.conf\"" }
- name: enable hostapd
become: true
systemd:
name: hostapd
enabled: yes
masked: no
state: restarted
tags: wireless_ap
- name: install dnsmasq
become: true
apt:
name: ['dnsmasq']
state: present
tags: wireless_ap
- name: configure dnsmasq
become: true
copy:
src: "{{ role_path }}/files/dnsmasq.conf"
dest: "/etc/dnsmasq.conf"
backup: yes
owner: root
group: root
tags: wireless_ap
- name: enable dnsmasq
become: true
systemd:
name: dnsmasq
enabled: yes
masked: no
state: restarted
tags: wireless_ap
- name: enable ipv4.forwarding
become: true
sysctl:
name: net.ipv4.ip_forward
value: 1
sysctl_set: yes
state: present
reload: yes
tags: wireless_ap
- name: copy fw config
become: true
copy:
src: "{{ role_path }}/files/iptables.ipv4.nat"
dest: "/etc/iptables.ipv4.nat"
backup: yes
owner: root
group: root
tags: wireless_ap
- name: iptables-restore to rc.local
lineinfile:
path: "/etc/rc.local"
state: present
insertbefore: "exit 0"
line: "iptables-restore < /etc/iptables.ipv4.nat"
become: true
tags: wireless_ap
- name: restart dhcpcd
become: true
systemd:
name: dhcpcd
enabled: yes
masked: no
state: restarted
tags: wireless_ap

View File

@@ -1,15 +1,15 @@
interface=wlan0
driver=nl80211
hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
ignore_broadcast_ssid=0
wpa=2
auth_algs=1
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
ssid={{ site_clli }}
wpa_passphrase=dsfinisdemo
interface=wlan0
driver=nl80211
hw_mode=g
channel=6
ieee80211n=1
wmm_enabled=1
ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]
macaddr_acl=0
ignore_broadcast_ssid=0
wpa=2
auth_algs=1
wpa_key_mgmt=WPA-PSK
rsn_pairwise=CCMP
ssid={{ site_clli }}
wpa_passphrase=dsfinisdemo

0
roles/youtube/files/youtube.sh Executable file → Normal file
View File

38
roles/youtube/tasks/main.yaml Executable file → Normal file
View File

@@ -1,19 +1,19 @@
---
- name: copy youtube script
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: pi
group: pi
mode: a+x
with_items:
- { src: "{{ role_path }}/files/youtube.sh", dest: "/home/pi/scripts/youtube.sh" }
tags: youtubetraff_script
- name: enable cron job for youtube traffic
cron:
name: "youtubetraff"
minute: "*/30"
hour: "7-18"
weekday: "1-5"
job: "/usr/bin/perl -e 'sleep int rand 900' && /home/pi/scripts/youtube.sh"
tags: youtubetraff_cron
---
- name: copy youtube script
copy:
src: "{{ item.src }}"
dest: "{{ item.dest }}"
owner: pi
group: pi
mode: a+x
with_items:
- { src: "{{ role_path }}/files/youtube.sh", dest: "/home/pi/scripts/youtube.sh" }
tags: youtubetraff_script
- name: enable cron job for youtube traffic
cron:
name: "youtubetraff"
minute: "*/30"
hour: "7-18"
weekday: "1-5"
job: "/usr/bin/perl -e 'sleep int rand 900' && /home/pi/scripts/youtube.sh"
tags: youtubetraff_cron