Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Koos85 committed Mar 7, 2024
1 parent 9ce633f commit 99a5028
Show file tree
Hide file tree
Showing 22 changed files with 778 additions and 20,666 deletions.
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# VSCode
.vscode

# Python
*.pyc
__pycache__/

# Test folder
testing/

# Target
target/
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ See the [SNMP probe](https://github.com/infrasonar/snmp-probe#config).
## Dry run

Available checks:
- `controller`
- `eventlog`
- `storage`
- `system`
- `disk`
- `fan`
- `psu`
- `temperature`
- `volume`

Create a yaml file, for example _(test.yaml)_:

```yaml
asset:
name: "foo.local"
check: "system"
check: "disk"
config:
address: "192.168.1.2"
```
Expand Down
66 changes: 0 additions & 66 deletions lib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,66 +0,0 @@
import struct
import time
from asyncsnmplib.mib.mib_index import MIB_INDEX
from asyncsnmplib.mib.syntax_funs import SYNTAX_FUNS


def on_eventlogtime(value: bytes):
'''
cpqHeEventLogUpdateTime OBJECT-TYPE
SYNTAX OCTET STRING (SIZE (6))
ACCESS read-only
STATUS mandatory
DESCRIPTION
"The time stamp when the event log entry was last modified.
field octets contents range
===== ====== ======== =====
1 1-2 year 0..65536
2 3 month 1..12
3 4 day 1..31
4 5 hour 0..23
5 6 minute 0..59
The year field is set with the most significant octet first.
A value of 0 in the year indicates an unknown time stamp."
src: CPQHLTH-MIB.mib
'''
# some devices seem to return 7 octets, thus we break at [:6] to strip the
# last octect(s)
timetuple = struct.unpack('>HBBBB', value[:6])
ts = int(time.mktime(timetuple + (0, 0, 0, -1)))
return ts


def on_phydrvids(value: bytes):
'''
cpqDaLogDrvPhyDrvIDs OBJECT-TYPE
SYNTAX OCTET STRING (SIZE (0..255))
ACCESS read-only
STATUS deprecated
DESCRIPTION
"Drive Array Logical Drive Physical Drive IDs.
This lists the physical drive IDs which are associated with this
logical drive. These are the same IDs which can be used as
indices into the physical drive table. Each byte of the string
is an index. For array controllers that support a larger number
of drives, the Drive Array Logical Drive Extended Physical
Drive Attachment Table should be used to determine drive
associations."
::= { cpqDaLogDrvEntry 10 }
'''
return list(map(int, value))


SYNTAX_FUNS['hp_eventlogtime'] = on_eventlogtime
SYNTAX_FUNS['hp_phydrvids'] = on_phydrvids

# patch the syntax function because we need the raw bytes for these metrics
MIB_INDEX[MIB_INDEX['CPQHLTH-MIB']['cpqHeEventLogInitialTime']]['syntax'] = {
'tp': 'CUSTOM', 'func': 'hp_eventlogtime',
}
MIB_INDEX[MIB_INDEX['CPQHLTH-MIB']['cpqHeEventLogUpdateTime']]['syntax'] = {
'tp': 'CUSTOM', 'func': 'hp_eventlogtime',
}
MIB_INDEX[MIB_INDEX['CPQIDA-MIB']['cpqDaLogDrvPhyDrvIDs']]['syntax'] = {
'tp': 'CUSTOM', 'func': 'hp_phydrvids',
}
Binary file removed lib/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file removed lib/__pycache__/snmpquery.cpython-39.pyc
Binary file not shown.
Binary file removed lib/__pycache__/version.cpython-39.pyc
Binary file not shown.
Binary file removed lib/check/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file removed lib/check/__pycache__/unifi.cpython-39.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions lib/check/controller.py → lib/check/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from ..utils import get_data

QUERIES = (
MIB_INDEX['CPQIDA-MIB']['cpqDaCntlrEntry'],
MIB_INDEX['READYNAS-MIB']['diskEntry'],
)


async def check_controller(
async def check_disk(
asset: Asset,
asset_config: dict,
check_config: dict):
Expand Down
5 changes: 2 additions & 3 deletions lib/check/storage.py → lib/check/fan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
from ..utils import get_data

QUERIES = (
MIB_INDEX['CPQIDA-MIB']['cpqDaLogDrvEntry'],
MIB_INDEX['CPQIDA-MIB']['cpqDaPhyDrvEntry'],
MIB_INDEX['READYNAS-MIB']['fanEntry'],
)


async def check_storage(
async def check_fan(
asset: Asset,
asset_config: dict,
check_config: dict):
Expand Down
6 changes: 2 additions & 4 deletions lib/check/eventlog.py → lib/check/psu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
from ..utils import get_data

QUERIES = (
MIB_INDEX['CPQHLTH-MIB']['cpqHeEventLogEntry'],
MIB_INDEX['READYNAS-MIB']['psuEntry'],
)


async def check_eventlog(
async def check_psu(
asset: Asset,
asset_config: dict,
check_config: dict):

state = await get_data(asset, asset_config, check_config, QUERIES)
for item in state.get('cpqHeEventLogEntry', []):
item.pop('cpqHeEventLogFreeFormData', None)
return state
63 changes: 0 additions & 63 deletions lib/check/system.py

This file was deleted.

16 changes: 16 additions & 0 deletions lib/check/temperature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from asyncsnmplib.mib.mib_index import MIB_INDEX
from libprobe.asset import Asset
from ..utils import get_data

QUERIES = (
MIB_INDEX['READYNAS-MIB']['temperatureEntry'],
)


async def check_temperature(
asset: Asset,
asset_config: dict,
check_config: dict):

state = await get_data(asset, asset_config, check_config, QUERIES)
return state
16 changes: 16 additions & 0 deletions lib/check/volume.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from asyncsnmplib.mib.mib_index import MIB_INDEX
from libprobe.asset import Asset
from ..utils import get_data

QUERIES = (
MIB_INDEX['READYNAS-MIB']['volumeEntry'],
)


async def check_volume(
asset: Asset,
asset_config: dict,
check_config: dict):

state = await get_data(asset, asset_config, check_config, QUERIES)
return state
2 changes: 1 addition & 1 deletion lib/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Version string. Examples:
# '3.0.0'
# '3.0.0-alpha9'
__version__ = '3.0.3'
__version__ = '3.0.0'
18 changes: 10 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
from libprobe.probe import Probe
from lib.check.controller import check_controller
from lib.check.eventlog import check_eventlog
from lib.check.storage import check_storage
from lib.check.system import check_system
from lib.check.disk import check_disk
from lib.check.fan import check_fan
from lib.check.psu import check_psu
from lib.check.temperature import check_temperature
from lib.check.volume import check_volume
from lib.version import __version__ as version


if __name__ == '__main__':
checks = {
'controller': check_controller,
'eventlog': check_eventlog,
'storage': check_storage,
'system': check_system,
'disk': check_disk,
'fan': check_fan,
'psu': check_psu,
'temperature': check_temperature,
'volume': check_volume,
}

probe = Probe("readynas", version, checks)
Expand Down
Loading

0 comments on commit 99a5028

Please sign in to comment.