Skip to content

Commit

Permalink
Merge pull request #9 from jordiprats/master
Browse files Browse the repository at this point in the history
0.2.2
  • Loading branch information
jordiprats authored Feb 26, 2020
2 parents 386c0d3 + b530fd0 commit 99da536
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.2.2

* added auto ACL mode

## 0.2.1

* millora check snmpv3 user
Expand Down
12 changes: 12 additions & 0 deletions examples/auto_acl.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class { 'snmpd':
add_default_acls => false,
}

class { 'snmpd::loadavg': }

# snmpwalk -v3 -l authPriv -u v3testuser -a SHA -A "1234567890" -x AES -X "1234567890" 127.0.0.1 system

snmpd::acl { 'demo':
community => $::eyp_snmpd_acls['demo']['community'],
allowed_hosts => $::eyp_snmpd_acls['demo']['hosts'],
}
24 changes: 24 additions & 0 deletions lib/facter/eyp_snmpd_v1_and_v2c_acls.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
snmp_users = Facter::Util::Resolution.exec('bash -c \'grep com2sec /etc/snmp/snmpd.conf | awk "{ print \$2 }" | sort | uniq\'').to_s

unless snmp_users.nil? or snmp_users.empty?
# Facter.add('eyp_snmpd_acls') do
# setcode do
# snmp_users.split("\n")
# end
# end

snmp_acls = {}

for snmp_user in snmp_users.split("\n")
snmp_user_hosts = Facter::Util::Resolution.exec("bash -c 'grep com2sec /etc/snmp/snmpd.conf | grep #{snmp_user} | awk \"{ print \\$3 }\" | sort | uniq'").to_s.split("\n")
snmp_user_community = Facter::Util::Resolution.exec("bash -c 'grep com2sec /etc/snmp/snmpd.conf | grep #{snmp_user} | awk \"{ print \\$4 }\" | sort | head -n1'").to_s

snmp_acls[snmp_user] = { 'hosts' => snmp_user_hosts, 'community' => snmp_user_community }
end

Facter.add('eyp_snmpd_acls') do
setcode do
snmp_acls
end
end
end
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eyp-snmpd",
"version": "0.2.1",
"version": "0.2.2",
"author": "eyp",
"summary": "SNMP agent management",
"license": "Apache-2.0",
Expand Down

0 comments on commit 99da536

Please sign in to comment.