Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

much needed cleanup #76

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Support all non EOL rubies
AllCops:
TargetRubyVersion: 2.3

MethodLength:
Max: 200
Expand Down Expand Up @@ -29,6 +32,13 @@ RegexpLiteral:
Style/Documentation:
Enabled: false

Style/BlockLength:
Metrics/BlockLength:
Exclude:
- 'test/**/*.rb'
- 'sensu-plugins-windows.gemspec'

Style/SafeNavigation:
Enabled: false

Style/EndOfLine:
EnforcedStyle: lf # 99% of the maintainers use some unix and so we need to assume that linux line endings are used
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
language: ruby
cache:
- bundler
before_install:
- gem install bundler -v 2.0
install:
- bundle install
rvm:
- 2.0
- 2.1
- 2.2
- 2.3.0
- 2.4.1
notifications:
Expand All @@ -28,9 +27,6 @@ deploy:
on:
tags: true
all_branches: true
rvm: 2.0
rvm: 2.1
rvm: 2.2
rvm: 2.3.0
rvm: 2.4.1
repo: sensu-plugins/sensu-plugins-windows
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ Which is based on [Keep A Changelog](http://keepachangelog.com/)

## [Unreleased]

### Security
- updated yard dependency to `~> 0.9.11` per: https://nvd.nist.gov/vuln/detail/CVE-2017-17042 (@majormoses)
- updated rubocop dependency to `~> 0.51.0` per: https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-8418. (@majormoses)

### Breaking Changes
- drop EOL rubies `< 2.3` (@majormoses)
- bump `sensu-plugin` dependency from `~> 1.2` to `~> 4.0` you can read the changelog entries for [4.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#400---2018-02-17), [3.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#300---2018-12-04), and [2.0](https://github.com/sensu-plugins/sensu-plugin/blob/master/CHANGELOG.md#v200---2017-03-29) (@majormoses)

### Changed
- update `bundler` dependency (@majormoses)
- appeased the cops (@majormoses)

### Removed
- `codeclimate` (@majormoses)

## [2.9.1] - 2019-02-17
### Fixed
- check-windows-disk.rb: use the full path for CSV file path due to a bug in `wmic` (@jasiek191)
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in sensu-plugins-windows.gemspec
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

[![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-windows.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-windows)
[![Gem Version](https://badge.fury.io/rb/sensu-plugins-windows.svg)](http://badge.fury.io/rb/sensu-plugins-windows)
[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-windows/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-windows)
[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-windows/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-windows)
[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-windows.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-windows)
[![Appveyor status](https://ci.appveyor.com/api/projects/status/j6cg9tmxs6ivscrd/branch/master?svg=true)](https://ci.appveyor.com/project/majormoses/sensu-plugins-windows/branch/master)
[![Community Slack](https://slack.sensu.io/badge.svg)](https://slack.sensu.io/badge)

Expand Down
8 changes: 5 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'github/markup'
require 'redcarpet'
Expand All @@ -7,9 +9,9 @@ require 'yard'
require 'yard/rake/yardoc_task'

YARD::Rake::YardocTask.new do |t|
OTHER_PATHS = %w().freeze
OTHER_PATHS = %w[].freeze
t.files = ['lib/**/*.rb', 'bin/**/*.rb', OTHER_PATHS]
t.options = %w(--markup-provider=redcarpet --markup=markdown --main=README.md --files CHANGELOG.md)
t.options = %w[--markup-provider=redcarpet --markup=markdown --main=README.md --files CHANGELOG.md]
end

RuboCop::RakeTask.new
Expand All @@ -35,4 +37,4 @@ task :check_binstubs do
end
end

task default: [:spec, :make_bin_executable, :yard, :rubocop, :check_binstubs]
task default: %i[spec make_bin_executable yard rubocop check_binstubs]
6 changes: 1 addition & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ environment:
matrix:
- RUBY_VERSION: 24
- RUBY_VERSION: 23
- RUBY_VERSION: 22
- RUBY_VERSION: 21

install:
- set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
# appveyor does not seem to have a way to cleanup the env and does not actually start from scratch each time
- gem uninstall bundler --executables || true
- gem install bundler -v 1.7
- gem install bundler -v 2.0
- bundle install

build: off
Expand Down
2 changes: 2 additions & 0 deletions bin/check-windows-cpu-load.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# check-windows-cpu-load.rb
#
Expand Down
4 changes: 3 additions & 1 deletion bin/check-windows-disk.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# check-windows-disk.rb
#
Expand Down Expand Up @@ -79,7 +81,7 @@ def read_wmic
next if config[:ignoretype] && config[:ignoretype].include?(type)
next if config[:ignoremnt] && config[:ignoremnt].include?(mnt)
next if config[:ignorelabel] && config[:ignorelabel].match(label)
rescue
rescue StandardError
unknown "malformed line from df: #{line}"
end
# If label value is not set, the drive letter will end up in that column. Set mnt to label in that case.
Expand Down
5 changes: 4 additions & 1 deletion bin/check-windows-process.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# check-windows-process.rb
#
Expand Down Expand Up @@ -27,6 +29,7 @@
require 'optparse'
require 'time'
require 'win32ole'
require 'date'

options = {}
parser = OptionParser.new do |opts|
Expand Down Expand Up @@ -70,7 +73,7 @@
wmi.ExecQuery('select * from win32_process').each do |process|
next unless process.Name.downcase.include? options[:procname].downcase
if !options[:warn].nil?
delta_days = DateTime.now - DateTime.parse(process.CreationDate)
delta_days = DateTime.now - DateTime.parse(process.CreationDate) # rubocop:disable Style/DateTime
delta_secs = (delta_days * 24 * 60 * 60).to_i
if delta_secs > options[:warn]
puts "OK: #{process.Name} running more than #{options[:warn]} seconds."
Expand Down
2 changes: 2 additions & 0 deletions bin/check-windows-processor-queue-length.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# check-windows-processor-queue-length.rb
#
Expand Down
14 changes: 8 additions & 6 deletions bin/check-windows-ram.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# check-windows-ram.rb
#
Expand Down Expand Up @@ -38,13 +40,13 @@ class CheckWindowsRAMLoad < Sensu::Plugin::Check::CLI
proc: proc(&:to_i)

def acquire_ram_usage
temp_arr_1 = []
temp_arr_2 = []
IO.popen('typeperf -sc 1 "Memory\\Available bytes" ') { |io| io.each { |line| temp_arr_1.push(line) } }
temp = temp_arr_1[2].split(',')[1]
temp_arr1 = []
temp_arr2 = []
IO.popen('typeperf -sc 1 "Memory\\Available bytes" ') { |io| io.each { |line| temp_arr1.push(line) } }
temp = temp_arr1[2].split(',')[1]
ram_available_in_bytes = temp[1, temp.length - 3].to_f
IO.popen('wmic OS get TotalVisibleMemorySize /Value') { |io| io.each { |line| temp_arr_2.push(line) } }
total_ram = temp_arr_2[4].split('=')[1].to_f
IO.popen('wmic OS get TotalVisibleMemorySize /Value') { |io| io.each { |line| temp_arr2.push(line) } }
total_ram = temp_arr2[4].split('=')[1].to_f
total_ram_in_bytes = total_ram * 1000.0
ram_use_percent = (total_ram_in_bytes - ram_available_in_bytes) * 100.0 / total_ram_in_bytes
ram_use_percent.round(2)
Expand Down
2 changes: 2 additions & 0 deletions bin/check-windows-service.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# check-windows-service.rb
#
Expand Down
2 changes: 2 additions & 0 deletions bin/metric-windows-cpu-load.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# metric-windows-cpu-load.rb
#
Expand Down
2 changes: 2 additions & 0 deletions bin/metric-windows-disk-usage.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# metric-windows-disk-usage.rb
#
Expand Down
2 changes: 2 additions & 0 deletions bin/metric-windows-network.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# metric-windows-network.rb
#
Expand Down
2 changes: 2 additions & 0 deletions bin/metric-windows-processor-queue-length.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# metric-windows-processor-queue-length.rb
#
Expand Down
14 changes: 8 additions & 6 deletions bin/metric-windows-ram-usage.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# metric-windows-ram-usage.rb
#
Expand Down Expand Up @@ -36,14 +38,14 @@ class RamMetric < Sensu::Plugin::Metric::CLI::Graphite
default: Socket.gethostname.to_s

def acquire_ram_usage
temp_arr_1 = []
temp_arr_2 = []
temp_arr1 = []
temp_arr2 = []
timestamp = Time.now.utc.to_i
IO.popen('typeperf -sc 1 "Memory\\Available bytes" ') { |io| io.each { |line| temp_arr_1.push(line) } }
temp = temp_arr_1[2].split(',')[1]
IO.popen('typeperf -sc 1 "Memory\\Available bytes" ') { |io| io.each { |line| temp_arr1.push(line) } }
temp = temp_arr1[2].split(',')[1]
ram_available_in_bytes = temp[1, temp.length - 3].to_f
IO.popen('wmic OS get TotalVisibleMemorySize /Value') { |io| io.each { |line| temp_arr_2.push(line) } }
total_ram = temp_arr_2[4].split('=')[1].to_f
IO.popen('wmic OS get TotalVisibleMemorySize /Value') { |io| io.each { |line| temp_arr2.push(line) } }
total_ram = temp_arr2[4].split('=')[1].to_f
total_ram_in_bytes = total_ram * 1000.0
ram_use_percent = (total_ram_in_bytes - ram_available_in_bytes) * 100.0 / total_ram_in_bytes
[ram_use_percent.round(2), timestamp]
Expand Down
2 changes: 2 additions & 0 deletions bin/metric-windows-uptime.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# metric-windows-uptime.rb
#
Expand Down
2 changes: 2 additions & 0 deletions bin/powershell_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: false

#
# powershell_helper.rb
#
Expand Down
2 changes: 2 additions & 0 deletions lib/sensu-plugins-windows.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

require 'sensu-plugins-windows/version'
2 changes: 2 additions & 0 deletions lib/sensu-plugins-windows/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module SensuPluginsWindows
module Version
MAJOR = 2
Expand Down
15 changes: 8 additions & 7 deletions sensu-plugins-windows.gemspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Expand All @@ -10,7 +12,7 @@ Gem::Specification.new do |s|
s.description = 'Sensu plugins for Windows'
s.email = '<[email protected]>'
s.executables = Dir.glob('bin/**/*.rb').map { |file| File.basename(file) }
s.files = Dir.glob('{bin,lib}/**/*') + %w(LICENSE README.md CHANGELOG.md)
s.files = Dir.glob('{bin,lib}/**/*') + %w[LICENSE README.md CHANGELOG.md]
s.homepage = 'https://github.com/sensu-plugins/sensu-plugins-windows'
s.license = 'MIT'
s.metadata = { 'maintainer' => 'sensu-plugin',
Expand All @@ -22,20 +24,19 @@ Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.post_install_message = 'You can use the embedded Ruby by setting EMBEDDED_RUBY=true in /etc/default/sensu'
s.require_paths = ['lib']
s.required_ruby_version = '>= 2.0.0'
s.required_ruby_version = '>= 2.3.0'
s.summary = 'Sensu plugins for Windows'
s.test_files = s.files.grep(%r{^(test|spec|features)/})
s.version = SensuPluginsWindows::Version::VER_STRING

s.add_runtime_dependency 'sensu-plugin', '~> 1.2'
s.add_runtime_dependency 'sensu-plugin', '~> 4.0'

s.add_development_dependency 'bundler', '~> 1.7'
s.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
s.add_development_dependency 'bundler', '~> 2.0'
s.add_development_dependency 'github-markup', '~> 3.0'
s.add_development_dependency 'pry', '~> 0.10'
s.add_development_dependency 'rake', '~> 12.3'
s.add_development_dependency 'redcarpet', '~> 3.2'
s.add_development_dependency 'rubocop', '~> 0.40.0'
s.add_development_dependency 'rspec', '~> 3.1'
s.add_development_dependency 'yard', '~> 0.8'
s.add_development_dependency 'rubocop', '~> 0.51.0'
s.add_development_dependency 'yard', '~> 0.9.11'
end
2 changes: 2 additions & 0 deletions test/check-windows-disk.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../bin/check-windows-disk.rb'

describe CheckDisk do
Expand Down
2 changes: 2 additions & 0 deletions test/check-windows-service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative '../bin/check-windows-service.rb'

describe CheckWinService do
Expand Down
3 changes: 1 addition & 2 deletions test/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
require 'codeclimate-test-reporter'
CodeClimate::TestReporter.start
# frozen_string_literal: true