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

fix rubocop warnings #2738

Merged
merged 41 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3010bc7
fix: rubocop warnings
aschaber1 Mar 31, 2023
26742c1
feat: fix more problems
aschaber1 Mar 31, 2023
b98975d
feat!: upgrade ruby version to 3.0
aschaber1 Mar 31, 2023
7b25200
build: update github actions
aschaber1 Mar 31, 2023
5906f63
ci(ruby): update save-state to new format
aschaber1 Mar 31, 2023
1074b33
build: only build ruby 3.0+
aschaber1 Mar 31, 2023
21c3e8b
fix: rubocop fixes
aschaber1 Mar 31, 2023
79e1c8a
fix: rubocop fixes
aschaber1 Mar 31, 2023
36c3e97
refactor: move from ENV for home to Dir.home
aschaber1 Apr 3, 2023
d01cb89
feat: upgrade dependencies
aschaber1 Apr 3, 2023
a95770e
refactor: Lint/MissingSuper: Call super to initialize state of the pa…
aschaber1 Apr 3, 2023
012d095
style: avoid error by pushing Metrics/ParameterLists to 6
aschaber1 Apr 3, 2023
587fff3
refactor: various `rubocop -A` fixes
aschaber1 Apr 3, 2023
f853a14
style: avoid error by pushing Metrics/ClassLength to 200
aschaber1 Apr 3, 2023
fa865e4
refactor: rubocop autocorrect lib/oxidized/input/telnet.rb
aschaber1 Apr 3, 2023
d0f482f
build: add `rubocop-rake` and `rubocop-minitest` to `.rubocop.yml`
aschaber1 Apr 3, 2023
c2c8ba2
docs(Rakefile): add task description for task `version_set`
aschaber1 Apr 3, 2023
737c4ea
refactor(spec): fix Minitest/GlobalExpectations rubocop-minitest mess…
aschaber1 Apr 3, 2023
a1a159d
ci: update ci pipeline to new codecov action
aschaber1 Apr 3, 2023
2915ba7
build: downgrade bundler dependency for ruby 3.0
aschaber1 Apr 3, 2023
196523e
refactor: except Lint/DuplicateBranch: Duplicate branch body detected
aschaber1 Apr 3, 2023
90c6ccc
refactor: fix Lint/DuplicateBranch: Duplicate branch body detected
aschaber1 Apr 3, 2023
8d860f9
refactor: fix Style/RedundantArgument: Argument is redundant because …
aschaber1 Apr 3, 2023
2e223c4
refactor: Style/RedundantInitialize: Remove unnecessary empty initial…
aschaber1 Apr 3, 2023
8f95331
refactor: exception for Metrics/PerceivedComplexity: Perceived comple…
aschaber1 Apr 3, 2023
936892b
refactor: Layout/EmptyLinesAroundBlockBody: Extra empty line detected…
aschaber1 Apr 3, 2023
5c19162
refactor: allow Lint/EmptyBlock
aschaber1 Apr 3, 2023
96f8de7
test(input/ssh_spec): ament `forward_agent = false` to test, to compl…
aschaber1 Apr 3, 2023
9329a60
refactor(rubocop): move some exceptions from rubocop to rubocop_todo
aschaber1 Apr 3, 2023
fc089cb
refactor: Lint/MissingSuper: Call super to initialize state of the pa…
aschaber1 Apr 3, 2023
9e74e38
build: generate codecov even if build failed
aschaber1 Apr 3, 2023
11b94f5
build: integrate rubocop results into pull request
aschaber1 Apr 3, 2023
699a3c5
build: fix versions for rubocop linter
aschaber1 Apr 3, 2023
ca76ebc
build(ruby): enable `GITHUB_TOKEN` for `ubocop-linter-action`
aschaber1 Apr 3, 2023
eaacdc1
build(ruby): try another rubocop action
aschaber1 Apr 3, 2023
c25a27a
build(ruby): change rubocop action reporter to `github-pr-review`
aschaber1 Apr 3, 2023
ef78ebf
test(input/githubrepo_spec): fix rubocop problems
aschaber1 Apr 3, 2023
bc224bd
test(input/githubrepo_spec): skip tests for now
aschaber1 Apr 3, 2023
51e2f5a
docs: upgrade install docs to ruby 3
aschaber1 Apr 11, 2023
409f53e
fix(Oxidized::String): fails when strings are empty + tests
aschaber1 Apr 11, 2023
8f9137b
build: add html output for non-CI builds
aschaber1 Apr 11, 2023
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
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