Skip to content

Commit

Permalink
fix rubocop warnings (ytti#2738)
Browse files Browse the repository at this point in the history
* fix: rubocop warnings

* feat: fix more problems

* feat!: upgrade ruby version to 3.0

* build: update github actions

* ci(ruby): update save-state to new format

https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/

* build: only build ruby 3.0+

* fix: rubocop fixes

* fix: rubocop fixes

* refactor: move from ENV for home to Dir.home

* feat: upgrade dependencies

* refactor: Lint/MissingSuper: Call super to initialize state of the parent class

* style: avoid error by pushing Metrics/ParameterLists to 6

Metrics/ParameterLists: Avoid parameter lists longer than 5 parameters. [6/5]

* refactor: various `rubocop -A` fixes

* style: avoid error by pushing Metrics/ClassLength to 200

Metrics/ClassLength: Class has too many lines. [197/192]

* refactor: rubocop autocorrect lib/oxidized/input/telnet.rb

* build: add `rubocop-rake` and `rubocop-minitest` to `.rubocop.yml`

* docs(Rakefile): add task description for task `version_set`

* refactor(spec): fix Minitest/GlobalExpectations rubocop-minitest messages

* ci: update ci pipeline to new codecov action

* build: downgrade bundler dependency for ruby 3.0

* refactor: except Lint/DuplicateBranch: Duplicate branch body detected

* refactor: fix Lint/DuplicateBranch: Duplicate branch body detected

* refactor: fix Style/RedundantArgument: Argument is redundant because it is implied by default

* refactor: Style/RedundantInitialize: Remove unnecessary empty initialize method

* refactor: exception for Metrics/PerceivedComplexity: Perceived complexity for oxidized_expect is too high. [13/12]

* refactor: Layout/EmptyLinesAroundBlockBody: Extra empty line detected at block body end

* refactor: allow Lint/EmptyBlock

* test(input/ssh_spec): ament `forward_agent = false` to test, to comply with code

* refactor(rubocop): move some exceptions from rubocop to rubocop_todo

* refactor: Lint/MissingSuper: Call super to initialize state of the parent class

* build: generate codecov even if build failed

* build: integrate rubocop results into pull request

* build: fix versions for rubocop linter

* build(ruby): enable `GITHUB_TOKEN` for `ubocop-linter-action`

* build(ruby): try another rubocop action

* build(ruby): change rubocop action reporter to `github-pr-review`

* test(input/githubrepo_spec): fix rubocop problems

* test(input/githubrepo_spec): skip tests for now

* docs: upgrade install docs to ruby 3

* fix(Oxidized::String): fails when strings are empty + tests

* build: add html output for non-CI builds
  • Loading branch information
aschaber1 authored and nickhilliard committed Jun 15, 2023
1 parent 335cf85 commit d01b124
Show file tree
Hide file tree
Showing 54 changed files with 608 additions and 405 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publishdocker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- uses: actions/checkout@master
- name: Get Release Version
id: get_version
run: echo ::save-state name=RELEASE_VERSION::$(echo ${GITHUB_REF:10})
run: echo name=RELEASE_VERSION::$(echo ${GITHUB_REF:10}) >> $GITHUB_STATE
- name: Publish to Registry
uses: elgohr/Publish-Docker-Github-Action@master
with:
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,24 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.6', '2.7', '3.0']
ruby-version: ['3.0', '3.1', '3.2']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: rubocop
uses: reviewdog/action-rubocop@v2
with:
rubocop_version: gemfile
rubocop_extensions: rubocop-minitest:gemfile rubocop-rake:gemfile
reporter: github-pr-review
- name: Run tests
run: bundle exec rake
- uses: codecov/codecov-action@v3
if: ${{ always() }}
34 changes: 24 additions & 10 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ inherit_from: .rubocop_todo.yml

# Do not attempt to police vendored code
AllCops:
TargetRubyVersion: 2.3
NewCops: enable
TargetRubyVersion: 3.0
Exclude:
- 'vendor/**/*'

StringLiterals:
Style/StringLiterals:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false

LineLength:
Layout/LineLength:
Enabled: false

Lint/AmbiguousRegexpLiteral:
Expand Down Expand Up @@ -66,14 +67,27 @@ Style/Documentation:
Style/ParallelAssignment:
Enabled: false

Metrics/MethodLength:
Max: 45

## Metrics/AbcSize:
## Max: 28
##
## Metrics/MethodLength:
## Max: 20
##
## Metrics/ClassLength:
## Max: 140
##

Metrics/ClassLength:
Max: 200

## Metrics/CyclomaticComplexity:
## Max: 7

Metrics/BlockLength:
Max: 150

Metrics/ParameterLists:
Max: 6

Lint/EmptyBlock:
Enabled: false

require:
- rubocop-rake
- rubocop-minitest
139 changes: 95 additions & 44 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,54 +1,33 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2020-05-18 14:13:15 +0200 using RuboCop version 0.81.0.
# on 2023-04-03 06:53:54 UTC using RuboCop version 1.48.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
# Configuration parameters: AllowComments.
# Configuration parameters: AllowComments, AllowNil.
Lint/SuppressedException:
Exclude:
- 'lib/oxidized/input/ssh.rb'
- 'lib/oxidized/input/telnet.rb'
- 'lib/oxidized/nodes.rb'

# Offense count: 68
# Configuration parameters: IgnoredMethods.
# Offense count: 62
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 82

# Offense count: 18
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 142

# Offense count: 6
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 196
Max: 92

# Offense count: 11
# Configuration parameters: IgnoredMethods.
# Offense count: 16
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 14

# Offense count: 62
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 41
Max: 12

# Offense count: 1
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 6

# Offense count: 11
# Configuration parameters: IgnoredMethods.
# Offense count: 13
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 14
Max: 12

# Offense count: 1
Naming/AccessorMethodName:
Expand All @@ -73,8 +52,8 @@ Naming/MemoizedInstanceVariableName:
Exclude:
- 'lib/oxidized/string.rb'

# Offense count: 14
# Cop supports --auto-correct.
# Offense count: 9
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: PreferredName.
Naming/RescuedExceptionsVariableName:
Exclude:
Expand All @@ -85,39 +64,111 @@ Naming/RescuedExceptionsVariableName:
- 'lib/oxidized/config.rb'
- 'lib/oxidized/node.rb'
- 'lib/oxidized/nodes.rb'
- 'lib/oxidized/output/git.rb'
- 'lib/oxidized/output/gitcrypt.rb'
- 'lib/oxidized/source/sql.rb'

# Offense count: 2
Rake/DuplicateTask:
Exclude:
- 'Rakefile'

# Offense count: 1
Security/Eval:
Exclude:
- 'Rakefile'

# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, EnforcedStyle.
# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: nested, compact
Style/ClassAndModuleChildren:
Exclude:
- 'lib/oxidized/config/vars.rb'
- 'lib/oxidized/input/telnet.rb'
- 'lib/oxidized/nodes.rb'

# Offense count: 2
Style/ClassVars:
Exclude:
- 'lib/oxidized.rb'

# Offense count: 2
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: allowed_in_returns, forbidden
Style/DoubleNegation:
Exclude:
- 'lib/oxidized/cli.rb'
- 'lib/oxidized/hook/exec.rb'

# Offense count: 36
# Cop supports --auto-correct.
# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/GlobalStdStream:
Exclude:
- 'lib/oxidized.rb'

# Offense count: 3
Style/OpenStructUse:
Exclude:
- 'lib/oxidized/hook.rb'
- 'lib/oxidized/node.rb'
- 'spec/hook/githubrepo_spec.rb'

# Offense count: 27
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantRegexpCharacterClass:
Exclude:
- 'lib/oxidized/model/axos.rb'
- 'lib/oxidized/model/comtrol.rb'
- 'lib/oxidized/model/fabricos.rb'
- 'lib/oxidized/model/ironware.rb'
- 'lib/oxidized/model/mlnxos.rb'
- 'lib/oxidized/model/nxos.rb'
- 'lib/oxidized/model/slxos.rb'
- 'lib/oxidized/model/sonicos.rb'
- 'lib/oxidized/model/speedtouch.rb'
- 'lib/oxidized/model/telco.rb'
- 'lib/oxidized/model/ucs.rb'
- 'lib/oxidized/model/voltaire.rb'
- 'lib/oxidized/model/zhoneolt.rb'
- 'lib/oxidized/model/zynoscli.rb'

# Offense count: 37
# This cop supports safe autocorrection (--autocorrect).
Style/RedundantRegexpEscape:
Exclude:
- 'lib/oxidized/model/adva.rb'
- 'lib/oxidized/model/airfiber.rb'
- 'lib/oxidized/model/aosw.rb'
- 'lib/oxidized/model/c4cmts.rb'
- 'lib/oxidized/model/dellx.rb'
- 'lib/oxidized/model/eltex.rb'
- 'lib/oxidized/model/enterasys800.rb'
- 'lib/oxidized/model/netonix.rb'
- 'lib/oxidized/model/netscaler.rb'
- 'lib/oxidized/model/openbsd.rb'
- 'lib/oxidized/model/siklu.rb'
- 'lib/oxidized/model/slxos.rb'
- 'lib/oxidized/model/sonicos.rb'
- 'lib/oxidized/model/trango.rb'

# Offense count: 45
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Enabled: false

# Offense count: 31
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/SlicingWithRange:
Enabled: false

# Offense count: 81
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Style/StringConcatenation:
Enabled: false

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/ZeroLengthPredicate:
Exclude:
- 'lib/oxidized/core.rb'
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]

- Upgrade Ruby dependency to Ruby 3.0+
- model for PanOS & Panorama via HTTP API (@pv2b, @sts)
- model for MikroTik SwOS devicse (@sm-nessus)
- model for TrueNAS devices (@neilschelly)
Expand Down
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Oxidized

[![Build Status](https://github.com/ytti/oxidized/actions/workflows/ruby.yml/badge.svg)](https://github.com/ytti/oxidized/actions/workflows/ruby.yml)
[![codecov.io](https://codecov.io/gh/ytti/oxidized/coverage.svg?branch=master)](https://codecov.io/gh/ytti/oxidized?branch=master)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/5a90cb22db6a4d5ea23ad0dfb53fe03a)](https://www.codacy.com/app/ytti/oxidized?utm_source=github.com&utm_medium=referral&utm_content=ytti/oxidized&utm_campaign=Badge_Grade)
Expand Down Expand Up @@ -76,7 +77,7 @@ Check out the [Oxidized TREX 2014 presentation](http://youtu.be/kBQ_CTUuqeU#t=3h

### Debian and Ubuntu

Debian "buster" or newer and Ubuntu 17.10 (artful) or newer are recommended. On Ubuntu, begin by enabling the `universe`
Debian "buster" or newer and Ubuntu 17.10 (artful) or newer are recommended. On Ubuntu, begin by enabling the `universe`
repository (required for libssh2-1-dev):

```shell
Expand Down Expand Up @@ -104,8 +105,8 @@ Install Ruby 2.3 from [SCL](https://www.softwarecollections.org/en/scls/rhscl/rh

```shell
yum install centos-release-scl
yum install rh-ruby23 rh-ruby23-ruby-devel
scl enable rh-ruby23 bash
yum install rh-ruby30 rh-ruby30-ruby-devel
scl enable rh-ruby30 bash
```

The following additional packages will be required to build the dependencies:
Expand All @@ -120,12 +121,14 @@ Make sure you dont have any leftover ruby:
```yum erase ruby```

Then, install gpg key and rvm
```sudo gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB

```shell
sudo gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
curl -sSL https://get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm requirements run
rvm install 2.6.0
rvm use 2.6.0
rvm install 3.0
rvm use 3.0
```

Install oxidized requirements:
Expand All @@ -141,7 +144,6 @@ You can see where the wrapped gem is via
```rvm wrapper show oxidized```
Use that path in the oxidized.service file, restart the systemctl daemon, run oxidized by hand once, edit config file, start service.


### FreeBSD

[Use RVM to install Ruby v2.3](#installing-ruby-23-using-rvm), then install all required packages and gems:
Expand Down Expand Up @@ -368,7 +370,8 @@ The systemd service assumes that you have a user named 'oxidized' and that oxidi
```shell
sudo cp extra/oxidized.service /etc/systemd/system
```
2. Setup /var/run/

2. Setup `/var/run/`

```shell
mkdir /run/oxidized
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ task :test do
end

task build: %i[chmod version_set]

desc 'Set Gem Version'
task :version_set do
Oxidized.version_set
Bundler::GemHelper.instance.gemspec.version = Oxidized::VERSION
Expand Down
15 changes: 6 additions & 9 deletions extra/nagios_check_failing_nodes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,14 @@

json = JSON.parse(open("http://localhost:8888/nodes.json").read)
json.each do |node|
unless ARGV.empty?
next if ARGV[0] != node['name']
end
if not node['last'].nil?
if node['last']['status'] != 'success'
critical_nodes << node['name']
critical = true
end
else
next if !ARGV.empty? && (ARGV[0] != node['name'])

if node['last'].nil?
pending_nodes << node['name']
pending = true
elsif node['last']['status'] != 'success'
critical_nodes << node['name']
critical = true
end
end

Expand Down
Loading

0 comments on commit d01b124

Please sign in to comment.