Skip to content

Commit

Permalink
Merge pull request #4 from redBorder/improvement/fix_lint
Browse files Browse the repository at this point in the history
Improvement/fix lint
  • Loading branch information
jsotofernandez authored Jun 5, 2024
2 parents 07b4fbb + ad5289a commit a18adbf
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 115 deletions.
6 changes: 2 additions & 4 deletions resources/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
#
# Cookbook Name:: snmp
# Attributes:: default
#
# Cookbook:: snmp
# Attributes:: default
112 changes: 54 additions & 58 deletions resources/metadata.rb
Original file line number Diff line number Diff line change
@@ -1,71 +1,67 @@
name "snmp"
maintainer "Eric G. Wolfe"
maintainer_email "[email protected]"
license "Apache 2.0"
description "Installs/Configures snmp on redhat, centos, ubuntu, debian"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "0.1.2"
name 'snmp'
maintainer 'Eric G. Wolfe'
maintainer_email '[email protected]'
license 'Apache-2.0'
description 'Installs/Configures snmp on redhat, centos, ubuntu, debian'
version '0.1.2'

recipe "snmp", "Installs and configures snmpd"

%w{ ubuntu debian redhat centos scientific fedora }.each do |os|
%w(ubuntu debian redhat centos scientific fedora).each do |os|
supports os
end

attribute "snmp",
:display_name => "SNMP",
:description => "Hash of SNMP attributes",
:type => "hash"

attribute "snmp/service",
:display_name => "SNMPD",
:description => "SNMP Daemon name",
:calculated => true
attribute 'snmp',
display_name: 'SNMP',
description: 'Hash of SNMP attributes',
type: 'hash'

attribute "snmp/community",
:display_name => "Community String",
:description => "Community String, defaults to public",
:default => "public",
:required => "recommended"
attribute 'snmp/service',
display_name: 'SNMPD',
description: 'SNMP Daemon name',
calculated: true

attribute "snmp/syslocationVirtual",
:display_name => "syslocation Virtual",
:description => "syslocation for Virtual Machines",
:default => "Virtual Server",
:required => "optional"
attribute 'snmp/community',
display_name: 'Community String',
description: 'Community String, defaults to public',
default: 'public',
required: 'recommended'

attribute "snmp/syslocationPhysical",
:display_name => "syslocation Physical",
:description => "syslocation for Physical Machines",
:default => "Server Room",
:required => "optional"
attribute 'snmp/syslocationVirtual',
display_name: 'syslocation Virtual',
description: 'syslocation for Virtual Machines',
default: 'Virtual Server',
required: 'optional'

attribute "snmp/syscontact",
:display_name => "syscontact",
:description => "System Contact",
:default => "Root <root@localhost>",
:required => "optional"
attribute 'snmp/syslocationPhysical',
display_name: 'syslocation Physical',
description: 'syslocation for Physical Machines',
default: 'Server Room',
required: 'optional'

attribute "snmp/trapcommunity",
:display_name => "trapcommunity",
:description => "SNMP Trap Community",
:default => "public",
:required => "optional"
attribute 'snmp/syscontact',
display_name: 'syscontact',
description: 'System Contact',
default: 'Root <root@localhost>',
required: 'optional'

attribute "snmp/trapsinks",
:display_name => "trapsinks",
:description => "Trapsink hostnames for NMS systems",
:type => "array"
attribute 'snmp/trapcommunity',
display_name: 'trapcommunity',
description: 'SNMP Trap Community',
default: 'public',
required: 'optional'

attribute "snmp/full_systemview",
:display_name => "full_systemview",
:description => "Enable full systemview for NMS systems",
:default => "false",
:required => "recommended"
attribute 'snmp/trapsinks',
display_name: 'trapsinks',
description: 'Trapsink hostnames for NMS systems',
type: 'array'

attribute "snmp/install_utils",
:display_name => "install_utils",
:description => "Enable installation of SNMP utilities, like snmpwalk",
:default => "false",
:required => "optional"
attribute 'snmp/full_systemview',
display_name: 'full_systemview',
description: 'Enable full systemview for NMS systems',
default: 'false',
required: 'recommended'

attribute 'snmp/install_utils',
display_name: 'install_utils',
description: 'Enable installation of SNMP utilities, like snmpwalk',
default: 'false',
required: 'optional'
66 changes: 30 additions & 36 deletions resources/providers/config.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#
# Cookbook Name:: snmp
# Cookbook:: snmp
# Provider::config
#
# Copyright 2010, Eric G. Wolfe
# Copyright:: 2010, Eric G. Wolfe
# Based on Eric G. Wolfe recipe for snmp. Adapted to be a provider and to
# work on redborder environments by Pablo Nebrera and Alberto Rodriguez
#
Expand All @@ -17,7 +15,6 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

action :add do
begin
Expand All @@ -28,61 +25,58 @@
snmp_pass = new_resource.snmp_pass
config_dir = new_resource.config_dir

dnf_package "net-snmp" do
dnf_package 'net-snmp' do
action :upgrade
end

directory config_dir do
owner "root"
group "root"
mode "0755"
owner 'root'
group 'root'
mode '0755'
end

template "/etc/sysconfig/snmpd" do
source "snmpd.erb"
owner "root"
group "root"
mode 0644
template '/etc/sysconfig/snmpd' do
source 'snmpd.erb'
owner 'root'
group 'root'
mode '0644'
retries 2
cookbook "snmp"
variables(:hostname => hostname)
notifies :restart, "service[snmpd]", :delayed
cookbook 'snmp'
variables(hostname: hostname)
notifies :restart, 'service[snmpd]', :delayed
end

template "#{config_dir}/snmpd.conf" do
mode 0644
owner "root"
group "root"
source "snmpd.conf.erb"
mode '0644'
owner 'root'
group 'root'
source 'snmpd.conf.erb'
retries 2
cookbook "snmp"
variables(:community => community,
:cdomain => cdomain,
:hostname => hostname,
:snmp_pass => snmp_pass,
:snmp_username => snmp_username)
notifies :restart, "service[snmpd]", :delayed
cookbook 'snmp'
variables(community: community,
cdomain: cdomain,
hostname: hostname,
snmp_pass: snmp_pass,
snmp_username: snmp_username)
notifies :restart, 'service[snmpd]', :delayed
end

service "snmpd" do
service 'snmpd' do
ignore_failure true
supports :status => true, :reload => true, :restart => true
supports status: true, reload: true, restart: true
action([:start, :enable])
end

rescue
Chef::Log.error(e.message)
end
end
end

action :remove do
begin
service "snmpd" do
service 'snmpd' do
ignore_failure true
supports :status => true, :reload => true, :restart => true
supports status: true, reload: true, restart: true
action([:stop, :disable])
end
end
end


14 changes: 6 additions & 8 deletions resources/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#
# Cookbook Name:: snmp
# Cookbook:: snmp
# Recipe:: default
#

snmp_config "Configure snmp" do
hostname node["hostname"]
cdomain "redborder.cluster"
action :add
end
snmp_config 'Configure snmp' do
hostname node['hostname']
cdomain 'redborder.cluster'
action :add
end
16 changes: 7 additions & 9 deletions resources/resources/config.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# Cookbook Name:: snmp
#
# Cookbook:: snmp
# Resource:: config
#

actions :add, :remove
default_action :add

attribute :community, :kind_of => String, :default => "redborder"
attribute :cdomain, :kind_of => String, :default => "redborder.cluster"
attribute :hostname, :kind_of => String, :default => "localhost"
attribute :snmp_username, :kind_of => String, :default => "redborder"
attribute :snmp_pass, :kind_of => String, :default => "redborderP@ssw0rd"
attribute :config_dir, :kind_of => String, :default => "/etc/snmp"
attribute :community, kind_of: String, default: 'redborder'
attribute :cdomain, kind_of: String, default: 'redborder.cluster'
attribute :hostname, kind_of: String, default: 'localhost'
attribute :snmp_username, kind_of: String, default: 'redborder'
attribute :snmp_pass, kind_of: String, default: 'redborderP@ssw0rd'
attribute :config_dir, kind_of: String, default: '/etc/snmp'

0 comments on commit a18adbf

Please sign in to comment.