Skip to content
This repository has been archived by the owner on Dec 17, 2021. It is now read-only.

Commit

Permalink
chore: add pre-commit to main (#89)
Browse files Browse the repository at this point in the history
* chore: add pre-commit to snmp-trap

* chore: rename "lint" to "pre-commit"

* chore: fix snyk severity-threshold

* chore: change .flake8 ignore statements

* chore: add sarif-file flag, delete mypy part from pyproject.toml

* chore: change cla-assistant/github-action version
  • Loading branch information
omrozowicz-splunk authored Sep 16, 2021
1 parent 1aabea5 commit be123bd
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 120
19 changes: 7 additions & 12 deletions .github/workflows/build-test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,13 @@ jobs:
name: test-results-unit-python_${{ matrix.python-version }}
path: test-results/*

lint:
pre-commit:
runs-on: ubuntu-latest
name: Lint Code Base
steps:
- uses: actions/checkout@v2
with:
# Full git history is needed to get a proper list of changed files within `super-linter`
fetch-depth: 0
- name: Lint Code Base
uses: github/super-linter@v4
env:
VALIDATE_ALL_CODEBASE: false
DEFAULT_BRANCH: main
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/setup-python@v2
- uses: pre-commit/[email protected]

review_secrets:
name: security-detect-secrets
runs-on: ubuntu-latest
Expand Down Expand Up @@ -131,14 +124,16 @@ jobs:
uses: snyk/actions/python-3.8@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high --sarif-file-output=snyk.sarif
- name: Upload result to GitHub Code Scanning
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: snyk.sarif
build:
name: Build Release
needs:
- lint
- pre-commit
- test-unit
- review_secrets
- compliance-copyrights
Expand Down
1 change: 1 addition & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@ header:
- "LICENSE"
- "NOTICE"
- "*.lock"
- ".flake8"

comment: on-failure
38 changes: 38 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Copyright 2021 Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.
#
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-merge-conflict
- id: debug-statements
- repo: https://github.com/psf/black
rev: 21.8b0
hooks:
- id: black
- repo: https://github.com/PyCQA/isort
rev: 5.9.3
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.910
hooks:
- id: mypy
additional_dependencies: [types-all]
- repo: https://github.com/PyCQA/flake8
rev: 3.9.2
hooks:
- id: flake8
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ sc4snmp-traps = "splunk_connect_for_snmp_traps.snmp_trap_server:main"
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"


[tool.isort]
profile = "black"
3 changes: 2 additions & 1 deletion splunk_connect_for_snmp_traps/manager/mib_server_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ def get_translation(var_binds, mib_server_url):
logger.error(f"[-] Mib Server API Error with code: {resp.status_code}")
except Exception as e:
logger.error(
f"MIB server is unreachable! Error happened while communicating to MIB server to perform the Translation: {e}"
f"MIB server is unreachable! Error happened while communicating to MIB server to perform "
f"the Translation: {e}"
)

return trap_event_string
21 changes: 12 additions & 9 deletions splunk_connect_for_snmp_traps/manager/trap_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# debugging log for SNMPv3 trap
from pysnmp import debug
from pysnmp.carrier.asyncore.dgram import udp, udp6
from pysnmp.entity import engine, config
from pysnmp.entity import config, engine
from pysnmp.entity.rfc3413 import ntfrcv
from pysnmp.proto import rfc1902

Expand Down Expand Up @@ -65,8 +65,8 @@ def configure_trap_server(self):
# SecurityName <-> CommunityName mapping
"""
test snmptrap command:
v1:
sudo snmptrap -v 1 -c public localhost:2162 '1.2.3.4.5.6' '192.193.194.195' 6 99 '55' 1.11.12.13.14.15 s "teststring"
v1:
sudo snmptrap -v 1 -c public localhost:2162 '1.2.3.4.5.6' '192.193.194.195' 6 99 '55' 1.11.12.13.14.15 s "teststring" # noqa: E501
v2c:
sudo snmptrap -v 2c -c public localhost:2162 123 1.3.6.1.6.3.1.1.5.1 1.3.6.1.2.1.1.5.0 s test2
Expand All @@ -93,13 +93,13 @@ def configure_trap_server(self):
test snmptrap command:
user1: snmpv3test
sudo snmptrap -v 3 -e 0x8000000004030201 -l noAuthNoPriv -u snmpv3test localhost:2162 123 1.3.6.1.6.3.1.1.5.1
sudo snmptrap -v 3 -e 0x8000000004030201 -l authPriv -u snmpv3test -A AuthPass1 -X PrivPass2 localhost:2162 2 1.3.6.1.2.1.1.3.0
sudo snmptrap -v 3 -e 0x8000000004030201 -l authPriv -u snmpv3test -a MD5 -A AuthPass1 -x DES -X PrivPass2 localhost:2162 '' 1.3.6.1.4.1.8072.2.3.0.1 1.3.6.1.4.1.8072.2.3.2.1 i 60
sudo snmptrap -v 3 -e 0x8000000004030201 -l authPriv -u snmpv3test -A AuthPass1 -X PrivPass2 localhost:2162 2 1.3.6.1.2.1.1.3.0 # noqa: E501
sudo snmptrap -v 3 -e 0x8000000004030201 -l authPriv -u snmpv3test -a MD5 -A AuthPass1 -x DES -X PrivPass2 localhost:2162 '' 1.3.6.1.4.1.8072.2.3.0.1 1.3.6.1.4.1.8072.2.3.2.1 i 60 # noqa: E501
user2: snmpv3test2
sudo snmptrap -v 3 -e 0x8000000004030202 -l noAuthNoPriv -u snmpv3test2 localhost:2162 123 1.3.6.1.6.3.1.1.5.1
sudo snmptrap -v 3 -e 0x8000000004030202 -l authPriv -u snmpv3test2 -a SHA -A AuthPass11 -x AES -X PrivPass22 localhost:2162 '' 1.3.6.1.4.1.8072.2.3.0.1 1.3.6.1.4.1.8072.2.3.2.1 i 120
sudo snmptrap -v 3 -e 0x8000000004030202 -l authPriv -u snmpv3test2 -a SHA -A AuthPass11 -x AES -X PrivPass22 localhost:2162 '' 1.3.6.1.4.1.8072.2.3.0.1 1.3.6.1.4.1.8072.2.3.2.1 i 120 # noqa: E501
user3: snmpv3test3
sudo snmptrap -e 0x8000000004030203 -v3 -l noAuthNoPriv -u snmpv3test3 localhost:2162 123 1.3.6.1.6.3.1.1.5.1
"""
Expand Down Expand Up @@ -131,7 +131,10 @@ def configure_trap_server(self):
if securityengineId:
securityengineId = rfc1902.OctetString(hexValue=str(securityengineId))
logger.info(
f"V3 params: username: {username}, authprotocol: {user_config.get('authProtocol', None)}-{authprotocol}, authkey: {authkey}, privprotocol: {user_config.get('privProtocol', None)}-{privprotocol}, privkey: {privkey}, securityengineId: {securityengineId}"
f"V3 params: username: {username},"
f" authprotocol: {user_config.get('authProtocol', None)}-{authprotocol},"
f" authkey: {authkey}, privprotocol: {user_config.get('privProtocol', None)}-{privprotocol}, "
f"privkey: {privkey}, securityengineId: {securityengineId}"
)
config.addV3User(
self._snmp_engine,
Expand Down Expand Up @@ -198,7 +201,7 @@ def snmp_callback_function(
else:
header["Agent_Hostname"] = device_ip
logger.debug(f"device_ip={device_ip}")
except:
except: # noqa: E722
logger.debug(f"device_ip={device_ip}")
header["Agent_Hostname"] = device_ip
pass
Expand Down
2 changes: 1 addition & 1 deletion splunk_connect_for_snmp_traps/snmp_trap_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


def main():
logger.info(f"Startup Config")
logger.info("Startup Config")
parser = argparse.ArgumentParser()
parser.add_argument(
"-l",
Expand Down

0 comments on commit be123bd

Please sign in to comment.