feat: make ansible-lint happier
This commit is contained in:
58
roles/munin_client/files/mikrotikcpu_
Normal file
58
roles/munin_client/files/mikrotikcpu_
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/usr/bin/perl
|
||||
###############################################################################
|
||||
use diagnostics;
|
||||
use Net::SNMP;
|
||||
use strict;
|
||||
use warnings;
|
||||
###############################################################################
|
||||
my $CPUOID = ".1.3.6.1.2.1.25.3.3.1.2.1";
|
||||
my $SNMPCommunity = "public";
|
||||
my $SNMPPort = "161";
|
||||
|
||||
###############################################################################
|
||||
## Determine Hostname
|
||||
my $Host = undef;
|
||||
$0 =~ /mikrotikcpu_(.+)*$/;
|
||||
unless ($Host = $1) {
|
||||
exit 2;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
## Initiate SNMP Session
|
||||
my ($Session, $Error) = Net::SNMP->session (-hostname => $Host,
|
||||
-community => $SNMPCommunity,
|
||||
-port => $SNMPPort,
|
||||
-timeout => 60,
|
||||
-retries => 5,
|
||||
-version => 1);
|
||||
if (!defined($Session)) {
|
||||
die "Croaking: $Error";
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
## Configuration
|
||||
if ($ARGV[0] && $ARGV[0] eq "config") {
|
||||
print "host_name " . $Host . "\n";
|
||||
print "graph_args -l 0 -r --vertical-label percent --lower-limit 0 --upper-limit 100\n";
|
||||
print "graph_title CPU usage\n";
|
||||
print "graph_category system\n";
|
||||
print "graph_info This graph shows the router's CPU usage.\n";
|
||||
print "graph_order Total\n";
|
||||
print "graph_vlabel %\n";
|
||||
print "graph_scale no\n";
|
||||
print "Total.label CPU Usage\n";
|
||||
print "Total.draw AREA\n";
|
||||
print "Total.warning 60\n";
|
||||
print "Total.critical 90\n";
|
||||
$Session->close;
|
||||
exit;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
## Execution
|
||||
if (my $Result = $Session->get_request(-varbindlist => [$CPUOID])) {
|
||||
print "Total.value " . $Result->{$CPUOID} . "\n";
|
||||
$Session->close;
|
||||
exit;
|
||||
}
|
||||
|
87
roles/munin_client/files/mikrotikifrate_
Normal file
87
roles/munin_client/files/mikrotikifrate_
Normal file
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/perl
|
||||
###############################################################################
|
||||
#use diagnostics;
|
||||
use Net::SNMP;
|
||||
#use strict;
|
||||
#use warnings;
|
||||
###############################################################################
|
||||
my $SNMPCommunity = "public";
|
||||
my $SNMPPort = "161";
|
||||
|
||||
###############################################################################
|
||||
## Determine Hostname
|
||||
my $Host = undef;
|
||||
my $ifname = undef;
|
||||
my $OID = ".1.3.6.1.2.1.2.2.1.2";
|
||||
$0 =~ /mikrotikifrate_(.+)*$/;
|
||||
|
||||
unless ($Host = $1) {
|
||||
exit 2;
|
||||
}
|
||||
|
||||
my @str = split(/_/, $Host);
|
||||
$Host = $str[0];
|
||||
$ifname = $str[1];
|
||||
|
||||
###############################################################################
|
||||
## Initiate SNMP Session
|
||||
my ($Session, $Error) = Net::SNMP->session (-hostname => $Host,
|
||||
-community => $SNMPCommunity,
|
||||
-port => $SNMPPort,
|
||||
-timeout => 10,
|
||||
-retries => 3,
|
||||
-version => 2);
|
||||
if (!defined($Session)) {
|
||||
die "Croaking: $Error";
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
## Find interface OID
|
||||
my $walkresult = $Session->get_table($OID);
|
||||
my @match = undef;
|
||||
while ( my ($id, $value) = each(%$walkresult) ) {
|
||||
if ( $value eq $ifname ) {
|
||||
@match = ("$id","$value");
|
||||
}
|
||||
}
|
||||
|
||||
@str = split(/\./, $match[0]);
|
||||
my $IFACEID = $str[-1];
|
||||
my $IFACEOID = ".1.3.6.1.2.1.2.2.1.2.".$IFACEID;
|
||||
my $IFACEBYTESIN = ".1.3.6.1.2.1.31.1.1.1.6.".$IFACEID;
|
||||
my $IFACEBYTESOUT = ".1.3.6.1.2.1.31.1.1.1.10.".$IFACEID;
|
||||
|
||||
###############################################################################
|
||||
## Configuration
|
||||
if ($ARGV[0] && $ARGV[0] eq "config") {
|
||||
print "host_name " . $Host . "\n";
|
||||
print "graph_args --base 1000\n";
|
||||
print "graph_title " . $ifname . " traffic\n";
|
||||
print "graph_vlabel bits per second\n";
|
||||
print "graph_category network\n";
|
||||
print "graph_info This graph shows the incoming and outgoing traffic rate of an interface\n";
|
||||
print "in.label received\n";
|
||||
print "in.type DERIVE\n";
|
||||
print "in.draw AREA\n";
|
||||
print "in.min 0\n";
|
||||
print "in.cdef in,8,*\n";
|
||||
print "out.label sent\n";
|
||||
print "out.type DERIVE\n";
|
||||
print "out.draw LINE1\n";
|
||||
print "out.min 0\n";
|
||||
print "out.cdef out,8,*\n";
|
||||
$Session->close;
|
||||
exit;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
## Execution
|
||||
if (my $Result = $Session->get_request(-varbindlist => [$IFACEBYTESIN, $IFACEBYTESOUT])) {
|
||||
print "in.value " . $Result->{$IFACEBYTESIN} . "\n";
|
||||
print "out.value " . $Result->{$IFACEBYTESOUT} . "\n";
|
||||
$Session->close;
|
||||
exit;
|
||||
}
|
||||
|
||||
$Session->close;
|
||||
exit;
|
59
roles/munin_client/files/mikrotikmemory_
Normal file
59
roles/munin_client/files/mikrotikmemory_
Normal file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/perl
|
||||
###############################################################################
|
||||
use diagnostics;
|
||||
use Net::SNMP;
|
||||
use strict;
|
||||
use warnings;
|
||||
###############################################################################
|
||||
my $MemTotalOID = ".1.3.6.1.2.1.25.2.3.1.5.65536";
|
||||
my $MemUsedOID = ".1.3.6.1.2.1.25.2.3.1.6.65536";
|
||||
my $SNMPCommunity = "public";
|
||||
my $SNMPPort = "161";
|
||||
|
||||
###############################################################################
|
||||
## Determine Hostname
|
||||
my $Host = undef;
|
||||
$0 =~ /mikrotikmemory_(.+)*$/;
|
||||
unless ($Host = $1) {
|
||||
exit 2;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
## Initiate SNMP Session
|
||||
my ($Session, $Error) = Net::SNMP->session (-hostname => $Host,
|
||||
-community => $SNMPCommunity,
|
||||
-port => $SNMPPort,
|
||||
-timeout => 60,
|
||||
-retries => 5,
|
||||
-version => 1);
|
||||
if (!defined($Session)) {
|
||||
die "Croaking: $Error";
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
## Configuration
|
||||
if ($ARGV[0] && $ARGV[0] eq "config") {
|
||||
my $Result = $Session->get_request(-varbindlist => [$MemTotalOID]);
|
||||
print "host_name " . $Host . "\n";
|
||||
print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit " . ($Result->{$MemTotalOID} * 1024) . "\n";
|
||||
print "graph_title Memory usage\n";
|
||||
print "graph_category system\n";
|
||||
print "graph_info This graph shows the router's memory usage.\n";
|
||||
print "graph_order Total Used\n";
|
||||
print "graph_vlabel bytes\n";
|
||||
print "Total.label Total Memory\n";
|
||||
print "Total.draw AREA\n";
|
||||
print "Used.label Used Memory\n";
|
||||
print "Used.draw AREA\n";
|
||||
$Session->close;
|
||||
exit;
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
## Execution
|
||||
if (my $Result = $Session->get_request(-varbindlist => [$MemTotalOID, $MemUsedOID])) {
|
||||
print "Total.value " . ($Result->{$MemTotalOID} * 1024) . "\n";
|
||||
print "Used.value " . ($Result->{$MemUsedOID} * 1024) . "\n";
|
||||
$Session->close;
|
||||
exit;
|
||||
}
|
6
roles/munin_client/handlers/main.yml
Normal file
6
roles/munin_client/handlers/main.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
|
||||
- name: restart munin-node
|
||||
service:
|
||||
name: munin-node
|
||||
state: restarted
|
11
roles/munin_client/tasks/hypervisors.yml
Normal file
11
roles/munin_client/tasks/hypervisors.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
---
|
||||
|
||||
- name: delete squid plugins
|
||||
shell: "rm -f /etc/munin/plugins/squid_*"
|
||||
notify:
|
||||
- restart munin-node
|
||||
|
||||
- name: delete lxc interfaces plugins
|
||||
shell: "rm -f /etc/munin/plugins/if_*veth* /etc/munin/plugins/if_*fw* /etc/munin/plugins/if_*vmbr*"
|
||||
notify:
|
||||
- restart munin-node
|
126
roles/munin_client/tasks/main.yml
Normal file
126
roles/munin_client/tasks/main.yml
Normal file
@@ -0,0 +1,126 @@
|
||||
---
|
||||
|
||||
- set_fact:
|
||||
muninpkgs:
|
||||
- muninlite
|
||||
munin_need_reconfigure: false
|
||||
when: ansible_facts['distribution'] == "LEDE" or ansible_facts['distribution'] == "OpenWRT" or ansible_facts['distribution'] == "OpenWrt"
|
||||
|
||||
- set_fact:
|
||||
muninpkgs:
|
||||
- munin-node
|
||||
- munin-plugins-core
|
||||
- munin-plugins-extra
|
||||
munin_need_reconfigure: true
|
||||
when: ansible_facts['distribution'] == "Debian"
|
||||
|
||||
- name: install munin node packages
|
||||
package:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
loop: "{{ muninpkgs }}"
|
||||
|
||||
- name: munin-node conf file
|
||||
template:
|
||||
src: munin-node.conf.j2
|
||||
dest: /etc/munin/munin-node.conf
|
||||
notify:
|
||||
- restart munin-node
|
||||
when: munin_need_reconfigure
|
||||
|
||||
## Adding modules for specific functions
|
||||
# for NginX webservers
|
||||
- name: install LWP::UserAgent
|
||||
package:
|
||||
name: libwww-perl
|
||||
state: present
|
||||
notify:
|
||||
- restart munin-node
|
||||
when: "'webservers' in group_names or 'loadbalancers' in group_names"
|
||||
|
||||
# for HAProxy servers
|
||||
- name: add HAProxy backend module
|
||||
file:
|
||||
src: /usr/share/munin/plugins/haproxy_
|
||||
dest: /etc/munin/plugins/haproxy_current
|
||||
state: link
|
||||
notify:
|
||||
- restart munin-node
|
||||
when: "'loadbalancers' in group_names"
|
||||
|
||||
# For MariaDB servers
|
||||
- name: install Cache::Cache
|
||||
package:
|
||||
name: libcache-cache-perl
|
||||
state: present
|
||||
notify:
|
||||
- restart munin-node
|
||||
when: "'mariadbservers' in group_names"
|
||||
|
||||
# For PGSQL servers
|
||||
- name: install DBD::Pg
|
||||
package:
|
||||
name: libdbd-pg-perl
|
||||
state: present
|
||||
notify:
|
||||
- restart munin-node
|
||||
when: "'pgsqlservers' in group_names"
|
||||
|
||||
# For Munin servers
|
||||
- name: execute specific tasks for munin servers
|
||||
include_tasks: mikrotik.yml
|
||||
when: "'muninservers' in group_names"
|
||||
|
||||
# for NUT (UPS) servers
|
||||
- name: "add specific nut value for UPS"
|
||||
file:
|
||||
path: "/etc/munin/plugins/nutups_eaton3s_{{ item }}"
|
||||
src: /usr/share/munin/plugins/nutups_
|
||||
state: link
|
||||
notify:
|
||||
- restart munin-node
|
||||
when: "'nut_server' in group_names"
|
||||
loop:
|
||||
- charge
|
||||
- voltages
|
||||
|
||||
# for physical servers
|
||||
- name: execute specific tasks for physical servers
|
||||
include_tasks: physical_servers.yml
|
||||
when: "'hypervisors' in group_names"
|
||||
|
||||
- name: reconfigure munin-node
|
||||
shell:
|
||||
cmd: munin-node-configure --shell | sh
|
||||
notify:
|
||||
- restart munin-node
|
||||
when: munin_need_reconfigure
|
||||
|
||||
## Useless junks for everyone
|
||||
- name: delete useless junks for everyone
|
||||
file:
|
||||
path: "/etc/munin/plugins/{{ item }}"
|
||||
state: absent
|
||||
when: munin_need_reconfigure
|
||||
loop:
|
||||
- users
|
||||
|
||||
## Useless junks for LXC
|
||||
- name: "delete junks from LXC machines"
|
||||
file:
|
||||
path: "/etc/munin/plugins/{{ item }}"
|
||||
state: absent
|
||||
notify:
|
||||
- restart munin-node
|
||||
when: ansible_facts['virtualization_type'] == "lxc"
|
||||
loop:
|
||||
- acpi
|
||||
- cpuspeed
|
||||
- diskstats
|
||||
- entropy
|
||||
- irqstats
|
||||
|
||||
## Useless junks for hypervisors
|
||||
- name: execute delete states for hypervisors
|
||||
include_tasks: hypervisors.yml
|
||||
when: "'hypervisors' in group_names"
|
21
roles/munin_client/tasks/mikrotik.yml
Normal file
21
roles/munin_client/tasks/mikrotik.yml
Normal file
@@ -0,0 +1,21 @@
|
||||
---
|
||||
|
||||
- name: deploy mikrotik unitary scripts
|
||||
copy:
|
||||
src: "./files/{{ item.0 }}"
|
||||
dest: "/etc/munin/plugins/{{ item.0 }}{{ item.1.name }}"
|
||||
mode: 0755
|
||||
loop: "{{ mikrotik_unitary_scripts|product(mikrotik_hosts)|list }}"
|
||||
notify:
|
||||
- restart munin-node
|
||||
|
||||
- name: deploy mikrotik per iface scripts
|
||||
copy:
|
||||
src: "./files/{{ item.1 }}"
|
||||
dest: "/etc/munin/plugins/{{ item.1 }}{{ item.0.0.name }}_{{ item.0.1 }}"
|
||||
mode: 0755
|
||||
loop: "{{ mikrotik_hosts|subelements('ifaces')|product(mikrotik_periface_scripts) }}"
|
||||
loop_control:
|
||||
label: "{{ item.0.1 }}"
|
||||
notify:
|
||||
- restart munin-node
|
16
roles/munin_client/tasks/physical_servers.yml
Normal file
16
roles/munin_client/tasks/physical_servers.yml
Normal file
@@ -0,0 +1,16 @@
|
||||
---
|
||||
# for physical servers
|
||||
- name: install necessary packages for hypervisors
|
||||
package:
|
||||
name: lm-sensors
|
||||
state: present
|
||||
|
||||
- name: configure specific munin plugin
|
||||
file:
|
||||
path: "/etc/munin/plugins/sensors_{{ item }}"
|
||||
src: /usr/share/munin/plugins/sensors_
|
||||
state: link
|
||||
notify:
|
||||
- restart munin-node
|
||||
loop:
|
||||
- temp
|
64
roles/munin_client/templates/munin-node.conf.j2
Normal file
64
roles/munin_client/templates/munin-node.conf.j2
Normal file
@@ -0,0 +1,64 @@
|
||||
#
|
||||
# Example config-file for munin-node
|
||||
#
|
||||
|
||||
log_level 4
|
||||
log_file /var/log/munin/munin-node.log
|
||||
pid_file /var/run/munin/munin-node.pid
|
||||
|
||||
background 1
|
||||
setsid 1
|
||||
|
||||
user root
|
||||
group root
|
||||
|
||||
# This is the timeout for the whole transaction.
|
||||
# Units are in sec. Default is 15 min
|
||||
#
|
||||
# global_timeout 900
|
||||
|
||||
# This is the timeout for each plugin.
|
||||
# Units are in sec. Default is 1 min
|
||||
#
|
||||
# timeout 60
|
||||
|
||||
# Regexps for files to ignore
|
||||
ignore_file [\#~]$
|
||||
ignore_file DEADJOE$
|
||||
ignore_file \.bak$
|
||||
ignore_file %$
|
||||
ignore_file \.dpkg-(tmp|new|old|dist)$
|
||||
ignore_file \.rpm(save|new)$
|
||||
ignore_file \.pod$
|
||||
|
||||
# Set this if the client doesn't report the correct hostname when
|
||||
# telnetting to localhost, port 4949
|
||||
#
|
||||
host_name {{ inventory_hostname }}
|
||||
|
||||
# A list of addresses that are allowed to connect. This must be a
|
||||
# regular expression, since Net::Server does not understand CIDR-style
|
||||
# network notation unless the perl module Net::CIDR is installed. You
|
||||
# may repeat the allow line as many times as you'd like
|
||||
|
||||
allow ^{{ hostvars['munin.dmz.mateu.be']['ansible_default_ipv4']['address'].split('.')|join('\.') }}
|
||||
allow ^127\.0\.0\.1$
|
||||
allow ^::1$
|
||||
|
||||
# If you have installed the Net::CIDR perl module, you can use one or more
|
||||
# cidr_allow and cidr_deny address/mask patterns. A connecting client must
|
||||
# match any cidr_allow, and not match any cidr_deny. Note that a netmask
|
||||
# *must* be provided, even if it's /32
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# cidr_allow 127.0.0.1/32
|
||||
# cidr_allow 192.0.2.0/24
|
||||
# cidr_deny 192.0.2.42/32
|
||||
|
||||
# Which address to bind to;
|
||||
host *
|
||||
# host 127.0.0.1
|
||||
|
||||
# And which port
|
||||
port 4949
|
Reference in New Issue
Block a user