Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icinga-checks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Commits
8149f2ef
Commit
8149f2ef
authored
2 years ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
Snmp Synology: use include file
parent
20e89ef5
No related branches found
No related tags found
1 merge request
!68
6338 snmpv3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
check_snmp_includes
+51
-0
51 additions, 0 deletions
check_snmp_includes
check_snmp_synology
+17
-37
17 additions, 37 deletions
check_snmp_synology
with
68 additions
and
37 deletions
check_snmp_includes
0 → 100644
+
51
−
0
View file @
8149f2ef
#!/bin/sh
# ----------------------------------------------------------------------
# Variables
# ----------------------------------------------------------------------
SNMPAUTH
=
SNMPCONFIG
=
/etc/icinga2/snmp.cfg
SNMPCOMMUNITY
=
"public"
SNMPVERSION
=
"2c"
SNMPWALK
=
$(
which snmpwalk
)
SNMPGET
=
$(
which snmpget
)
SNMPTIMEOUT
=
3
SNMPTARGET
=
"127.0.0.1"
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
# read config data for authentication; it sets the variable SNMPAUTH
# that can be used for snmpwalk / snmpget
#
# no params
#
# used global vars:
# - SNMPVERSION + SNMPCOMMUNITY to set the default
# - SNMPCONFIG - filename of the config to read
# - SNMPTARGET - SNMPTARGET (ip or fqdn) of target to connect
#
read_config
(){
SNMPAUTH
=
"-v
$SNMPVERSION
-c
$SNMPCOMMUNITY
"
if
[
-r
"
$SNMPCONFIG
"
]
;
then
if
grep
"^
${
SNMPTARGET
}
:"
"
$SNMPCONFIG
"
>
/dev/null
;
then
SNMPAUTH
=
"
$(
grep
"^
${
SNMPTARGET
}
:"
"
$SNMPCONFIG
"
|
cut
-f
2-
-d
':'
)
"
else
SNMPAUTH
=
"
$(
grep
"^DEFAULT:"
"
$SNMPCONFIG
"
|
cut
-f
2-
-d
':'
)
"
fi
else
ph.setStatus
"unknown"
echo
"ERROR: unable to read config file [
$SNMPCONFIG
]."
ph.exit
fi
}
# ----------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
check_snmp_synology
+
17
−
37
View file @
8149f2ef
...
@@ -17,20 +17,13 @@
...
@@ -17,20 +17,13 @@
#---------------------------------------------------
#---------------------------------------------------
.
$(
dirname
$0
)
/inc_pluginfunctions
.
$(
dirname
$0
)
/inc_pluginfunctions
.
$(
dirname
$0
)
/check_snmp_includes
# --- basic vars
# --- basic vars
self_APPNAME
=
$(
basename
$0
|
tr
[
:lower:]
[
:upper:]
)
self_APPNAME
=
$(
basename
$0
|
tr
[
:lower:]
[
:upper:]
)
self_APPVERSION
=
1.2
self_APPVERSION
=
1.2
SNMPCOMMUNITY
=
"public"
SNMPVERSION
=
"2c"
SNMPWALK
=
$(
which snmpwalk
)
SNMPGET
=
$(
which snmpget
)
SNMPCONFIG
=
/etc/icingaclient/snmp.cfg
HOSTNAME
=
"localhost"
option_found
=
0
option_found
=
0
healthString
=
""
healthString
=
""
verbose
=
"no"
verbose
=
"no"
...
@@ -88,20 +81,22 @@ On higher cpu usage it can show processes that cause cpu waits and
...
@@ -88,20 +81,22 @@ On higher cpu usage it can show processes that cause cpu waits and
with most cpu consumption.
with most cpu consumption.
SYNTAX:
SYNTAX:
$_self
[options]
$_self
[options]
-h TARGET
OPTIONS:
OPTIONS:
-a authentication params for snmpwalk/ snmpget to connect to target;
-a STRING
default:
\"
-v2c -c public
\"
(Snmpv2 with community string
\"
public
\"
)
authentication params for snmpwalk/ snmpget to connect to target;
-h host to connect as hostname or ip address
default:
\"
-v2c -c public
\"
(Snmpv2 with community string
\"
public
\"
)
-f FILE
-h SNMPTARGET
read authentication from config file
as fqdn or ip address; default: localhost
default:
\"
/etc/icingaclient/snmp.cfg
\"
-f FILE
-v detailed output
read authentication from config file
default:
\"
/etc/icinga2/snmp.cfg
\"
-v detailed output
CONFIG FILE:
CONFIG FILE:
The config file can be multiline and has the syntax
The config file can be multiline and has the syntax
[
hostname
]:[auth parameters]
[
SNMPTARGET
]:[auth parameters]
The auth parameters set the version and all needed values to connect.
The auth parameters set the version and all needed values to connect.
Snmp v2 uses a community string.
Snmp v2 uses a community string.
Snmp v3 is highly recommended (you should disable Snmp v2) and needs
Snmp v3 is highly recommended (you should disable Snmp v2) and needs
...
@@ -114,7 +109,7 @@ CONFIG FILE:
...
@@ -114,7 +109,7 @@ CONFIG FILE:
EXAMPLE:
EXAMPLE:
$_self
-h server-01.example.com -v
$_self
-h server-01.example.com -v
Show Synology status of server-01 using connect data from /etc/icinga
client
/snmp.cfg
Show Synology status of server-01 using connect data from /etc/icinga
2
/snmp.cfg
$_self
-h server-01.example.com -v -f /opt/somewhere/snmp.conf
$_self
-h server-01.example.com -v -f /opt/somewhere/snmp.conf
Show Synology status of server-01 using connect data from custom config
Show Synology status of server-01 using connect data from custom config
...
@@ -144,21 +139,6 @@ usage()
...
@@ -144,21 +139,6 @@ usage()
ph.abort
"
$USAGE
"
ph.abort
"
$USAGE
"
}
}
read_config
(){
SNMPAUTH
=
"-v
$SNMPVERSION
-c
$SNMPCOMMUNITY
"
if
[
-r
"
$SNMPCONFIG
"
]
;
then
if
grep
"^
${
HOSTNAME
}
:"
"
$SNMPCONFIG
"
>
/dev/null
;
then
SNMPAUTH
=
"
$(
grep
"^
${
HOSTNAME
}
:"
"
$SNMPCONFIG
"
|
cut
-f
2-
-d
':'
)
"
else
SNMPAUTH
=
"
$(
grep
"^DEFAULT:"
"
$SNMPCONFIG
"
|
cut
-f
2-
-d
':'
)
"
fi
else
ph.setStatus
"unknown"
echo
"ERROR: unable to read config file [
$SNMPCONFIG
]."
ph.exit
fi
}
#---------------------------------------------------
#---------------------------------------------------
# MAIN
# MAIN
...
@@ -173,7 +153,7 @@ while getopts a:h:f:v OPTNAME; do
...
@@ -173,7 +153,7 @@ while getopts a:h:f:v OPTNAME; do
SNMPCONFIG
=
"
$OPTARG
"
SNMPCONFIG
=
"
$OPTARG
"
;;
;;
h
)
h
)
HOSTNAME
=
"
$OPTARG
"
SNMPTARGET
=
"
$OPTARG
"
option_found
=
1
option_found
=
1
;;
;;
v
)
v
)
...
@@ -191,8 +171,8 @@ done
...
@@ -191,8 +171,8 @@ done
test
-z
"
$SNMPAUTH
"
&&
read_config
test
-z
"
$SNMPAUTH
"
&&
read_config
# --- read raid and disks to get its single OIDs
# --- read raid and disks to get its single OIDs
nbDisk
=
$(
$SNMPWALK
-OQne
-t
10
${
SNMPAUTH
}
$
HOSTNAME
$OID_diskID
2> /dev/null |
wc
-l
)
nbDisk
=
"
$(
$SNMPWALK
-OQne
-t
$SNMPTIMEOUT
${
SNMPAUTH
}
$
SNMPTARGET
$OID_diskID
2> /dev/null |
wc
-l
)
"
nbRAID
=
$(
$SNMPWALK
-OQne
-t
10
${
SNMPAUTH
}
$
HOSTNAME
$OID_RAIDName
2> /dev/null |
wc
-l
)
nbRAID
=
"
$(
$SNMPWALK
-OQne
-t
$SNMPTIMEOUT
${
SNMPAUTH
}
$
SNMPTARGET
$OID_RAIDName
2> /dev/null |
wc
-l
)
"
for
i
in
$(
seq
1
$nbDisk
)
;
for
i
in
$(
seq
1
$nbDisk
)
;
do
do
...
@@ -204,7 +184,7 @@ do
...
@@ -204,7 +184,7 @@ do
done
done
# --- SNPGET to all wanted oids
# --- SNPGET to all wanted oids
syno
=
$(
$SNMPGET
-OQne
-t
10
${
SNMPAUTH
}
$
HOSTNAME
$OID_model
$OID_serialNumber
$OID_DSMVersion
$OID_DSMUpdateAvailable
$OID_systemStatus
$OID_powerStatus
$OID_systemFanStatus
$OID_CPUFanStatus
$OID_temp
$OID_disk
$OID_RAID
2> /dev/null |
sed
's/^[ \t]*//;s/[ \t]*$//'
)
syno
=
$(
$SNMPGET
-OQne
-t
$SNMPTIMEOUT
${
SNMPAUTH
}
$
SNMPTARGET
$OID_model
$OID_serialNumber
$OID_DSMVersion
$OID_DSMUpdateAvailable
$OID_systemStatus
$OID_powerStatus
$OID_systemFanStatus
$OID_CPUFanStatus
$OID_temp
$OID_disk
$OID_RAID
2> /dev/null |
sed
's/^[ \t]*//;s/[ \t]*$//'
)
if
[
"
$?
"
!=
"0"
]
;
then
if
[
"
$?
"
!=
"0"
]
;
then
ph.abort
"Problem with SNMP request"
ph.abort
"Problem with SNMP request"
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment