diff options
-rwxr-xr-x | collectors/snmpfetchng.pl | 29 | ||||
-rw-r--r-- | inventory-localhost | 4 | ||||
-rw-r--r-- | playbook-new.yml | 8 | ||||
-rw-r--r-- | roles/ping/files/gondul-pinger.service | 14 | ||||
-rw-r--r-- | roles/ping/handlers/main.yml | 3 | ||||
-rw-r--r-- | roles/ping/tasks/main.yml | 10 | ||||
-rw-r--r-- | roles/snmp/files/gondul-snmp.service | 14 | ||||
-rw-r--r-- | roles/snmp/handlers/main.yml | 3 | ||||
-rw-r--r-- | roles/snmp/tasks/main.yml | 23 | ||||
-rw-r--r-- | roles/web/tasks/main.yml | 1 |
10 files changed, 79 insertions, 30 deletions
diff --git a/collectors/snmpfetchng.pl b/collectors/snmpfetchng.pl index b1ee68a..1d352a1 100755 --- a/collectors/snmpfetchng.pl +++ b/collectors/snmpfetchng.pl @@ -56,15 +56,6 @@ sub mylog printf STDERR "[%s] %s\n", $time, $msg; } -# Hack to avoid starting the collector before graphite is up. -sleep(5); -my $sock = IO::Socket::IP->new( - PeerHost => "$nms::config::graphite_host:$nms::config::graphite_port", - Timeout => 20, - ) or die "Cannot connect to graphite - $@"; - - $sock->blocking( 0 ); - sub populate_switches { @switches = (); @@ -149,31 +140,11 @@ sub callback{ for my $nic (@nicids) { $tree2{'ports'}{$tree{$nic}{'ifName'}} = $tree{$nic}; - for my $tmp_key (keys $tree{$nic}) { - my $field = $tree{$nic}{'ifName'}; - $field =~ s/[^a-z0-9]/_/gi; - my $path = "snmp.$switch{'sysname'}.ports.$field.$tmp_key"; - my $value = $tree{$nic}{$tmp_key}; - if ($value =~ m/^\d+$/) { - print $sock "$path $value $now_graphite\n"; - } - - } delete $tree{$nic}; } for my $iid (keys %tree) { for my $key (keys %{$tree{$iid}}) { $tree2{'misc'}{$key}{$iid} = $tree{$iid}{$key}; - my $localiid = $iid; - if ($localiid eq "") { - $localiid = "_"; - } - $localiid =~ s/[^a-z0-9]/_/gi; - my $path = "snmp.$switch{'sysname'}.misc.$key.$localiid"; - my $value = $tree{$iid}{$key}; - if ($value =~ m/^\d+$/) { - print $sock "$path $value $now_graphite\n"; - } } } if ($total > 0) { diff --git a/inventory-localhost b/inventory-localhost index 1b56b6e..ee4e0bc 100644 --- a/inventory-localhost +++ b/inventory-localhost @@ -4,3 +4,7 @@ localhost ansible_connection=local localhost ansible_connection=local [web] localhost ansible_connection=local +[ping] +localhost ansible_connection=local +[snmp] +localhost ansible_connection=local diff --git a/playbook-new.yml b/playbook-new.yml index 38d43c1..7961f21 100644 --- a/playbook-new.yml +++ b/playbook-new.yml @@ -10,4 +10,12 @@ become: true roles: - web +- hosts: ping + become: true + roles: + - ping +- hosts: snmp + become: true + roles: + - snmp diff --git a/roles/ping/files/gondul-pinger.service b/roles/ping/files/gondul-pinger.service new file mode 100644 index 0000000..fc9cabd --- /dev/null +++ b/roles/ping/files/gondul-pinger.service @@ -0,0 +1,14 @@ +[Unit] +Description=Gondul ping collector +Documentation=http://google.com +After=network.target + +[Service] +ExecStart=/opt/gondul/collectors/ping.pl +MountFlags=slave +LimitNOFILE=1048576 +LimitNPROC=1048576 +LimitCORE=infinity + +[Install] +WantedBy=multi-user.target diff --git a/roles/ping/handlers/main.yml b/roles/ping/handlers/main.yml new file mode 100644 index 0000000..6592e88 --- /dev/null +++ b/roles/ping/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart gondul-pinger + service: name=gondul-pinger state=restarted diff --git a/roles/ping/tasks/main.yml b/roles/ping/tasks/main.yml new file mode 100644 index 0000000..cb435d1 --- /dev/null +++ b/roles/ping/tasks/main.yml @@ -0,0 +1,10 @@ +- name: Add systemd service file for gondul-ping + copy: + dest: /etc/systemd/system/gondul-pinger.service + src: gondul-pinger.service + notify: restart gondul-pinger +- name: Enable ping service + systemd: + name: gondul-pinger.service + enabled: yes + notify: restart gondul-pinger diff --git a/roles/snmp/files/gondul-snmp.service b/roles/snmp/files/gondul-snmp.service new file mode 100644 index 0000000..e5f2179 --- /dev/null +++ b/roles/snmp/files/gondul-snmp.service @@ -0,0 +1,14 @@ +[Unit] +Description=Gondul snmp collector +Documentation=http://google.com +After=network.target + +[Service] +ExecStart=/opt/gondul/collectors/snmpfetchng.pl +MountFlags=slave +LimitNOFILE=1048576 +LimitNPROC=1048576 +LimitCORE=infinity + +[Install] +WantedBy=multi-user.target diff --git a/roles/snmp/handlers/main.yml b/roles/snmp/handlers/main.yml new file mode 100644 index 0000000..b0232f2 --- /dev/null +++ b/roles/snmp/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart gondul-snmp + service: name=gondul-snmp state=restarted diff --git a/roles/snmp/tasks/main.yml b/roles/snmp/tasks/main.yml new file mode 100644 index 0000000..2cb7165 --- /dev/null +++ b/roles/snmp/tasks/main.yml @@ -0,0 +1,23 @@ +- file: + path: /opt/gondul/data + state: directory + mode: 0755 +- stat: + path: /opt/gondul/data/mibs + register: mibdir +- name: Get mibs + command: /opt/gondul/extras/tools/get_mibs.sh + args: + chdir: /opt/gondul/data/ + when: not mibdir.stat.exists + notify: restart gondul-snmp +- name: Add systemd service file for gondul-snmp + copy: + dest: /etc/systemd/system/gondul-snmp.service + src: gondul-snmp.service + notify: restart gondul-snmp +- name: Enable snmp service + systemd: + name: gondul-snmp.service + enabled: yes + notify: restart gondul-snmp diff --git a/roles/web/tasks/main.yml b/roles/web/tasks/main.yml index e67e6ce..b716f87 100644 --- a/roles/web/tasks/main.yml +++ b/roles/web/tasks/main.yml @@ -37,7 +37,6 @@ notify: restart apache - command: a2dissite 000-default ignore_errors: true - notify: restart apache - name: Enable gondul-config copy: dest: /etc/apache2/sites-enabled/ |