Munin pour le switch

This commit is contained in:
VC
2024-07-05 11:53:06 +02:00
parent 6daf5cffbf
commit b004e372ae
2 changed files with 77 additions and 0 deletions

View 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;
}

View File

@@ -0,0 +1,18 @@
# For Munin servers
- 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) }}"
notify:
- restart munin-node