Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
grafana_scripts_public
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dencur
grafana_scripts_public
Commits
c3fcf604
Commit
c3fcf604
authored
Oct 09, 2016
by
Curt Dennis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added JSON parsing from Cyber Power Panel to replace the previous cpupssmon.sh script
parent
60417496
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
6 deletions
+62
-6
upsmon.sh
upsmon.sh
+62
-6
No files found.
upsmon.sh
View file @
c3fcf604
...
...
@@ -16,21 +16,21 @@ get_ups_info () {
#-- Synology NAS --
#UPS Battery Voltage
syno_battvoltage
=
`
snmpget
-v
2c
-c
public 10.0.0.14 1.3.6.1.4.1.6574.4.3.2.1.0
-Ov
`
#UPS Battery Charge
#UPS Battery Charge
syno_battcharge
=
`
snmpget
-v
2c
-c
public 10.0.0.14 1.3.6.1.4.1.6574.4.3.1.1.0
-Ov
`
#UPS Load
#UPS Load
syno_battload
=
`
snmpget
-v
2c
-c
public 10.0.0.14 1.3.6.1.4.1.6574.4.2.12.1.0
-Ov
`
#UPS Input Voltage
syno_inputvoltage
=
`
snmpget
-v
2c
-c
public 10.0.0.14 1.3.6.1.4.1.6574.4.4.1.1.0
-Ov
`
#UPS Runtime
#UPS Runtime
syno_runtime
=
`
snmpget
-v
2c
-c
public 10.0.0.14 1.3.6.1.4.1.6574.4.3.6.1.0
-Ov
`
syno_battvoltage
=
$(
echo
$syno_battvoltage
|
cut
-c
16-
)
syno_battcharge
=
$(
echo
$syno_battcharge
|
cut
-c
16-
)
syno_battload
=
$(
echo
$syno_battload
|
cut
-c
16-
)
syno_inputvoltage
=
$(
echo
$syno_inputvoltage
|
cut
-c
16-
)
syno_runtime
=
$(
echo
$syno_runtime
|
cut
-c
10-
)
syno_battvoltage
=
$(
printf
"%.0f"
$syno_battvoltage
)
syno_battcharge
=
$(
printf
"%.0f"
$syno_battcharge
)
syno_battload
=
$(
printf
"%.0f"
$syno_battload
)
...
...
@@ -48,6 +48,33 @@ get_ups_info () {
}
get_ups_info_cpp
()
{
#-- Cyber Power Panel --
#Pull data from the Cyber Power Panel. Replace with your own IP.
cpp_json_data
=
$(
curl http://10.0.0.60:3052/agent/ppbe.js/init_status.js
)
#input voltage
cpp_involts
=
$(
echo
$cpp_json_data
|
grep
-oP
'(?<="voltage":")[^."]*'
|
head
-1
)
#battery voltage
cpp_battvolts
=
$(
echo
$cpp_json_data
|
grep
-oP
'(?<="voltage":")[^."]*'
|
tail
-1
)
#Load(Watts)
cpp_loadwatt
=
$(
echo
$cpp_json_data
|
grep
-oP
'(?<="watt":)[^,]*'
|
head
-1
)
#Capacity %
cpp_capacity
=
$(
echo
$cpp_json_data
|
grep
-oP
'(?<="capacity":)[^,]*'
|
head
-1
)
#Runtime
runtimeHour
=
$(
echo
$cpp_json_data
|
grep
-oP
'(?<="runtimeHour":)[^,]*'
|
head
-1
)
runtimeMinute
=
$(
echo
$cpp_json_data
|
grep
-oP
'(?<="runtimeMinute":)[^,]*'
|
head
-1
)
cpp_runtime
=
$((
$runtimeHour
*
60
*
60
+
$runtimeMinute
*
60
))
#Load %
cpp_loadpercent
=
$(
echo
$cpp_json_data
|
grep
-oP
'(?<="load":)[^,]*'
|
head
-1
)
}
print_data
()
{
echo
"Synology UPS Battery Voltage:
$syno_battvoltage
"
echo
"Synology UPS Battery Charge:
$syno_battcharge
"
...
...
@@ -56,6 +83,15 @@ print_data () {
echo
"Synology UPS Runtime:
$syno_runtime
"
}
print_data_cpp
()
{
echo
"CPP UPS Battery Voltage:
$cpp_battvolts
"
echo
"CPP UPS Battery Charge:
$cpp_capacity
"
echo
"CPP UPS Load:
$cpp_loadpercent
"
echo
"CPP UPS Load(Watts):
$cpp_loadwatt
"
echo
"CPP UPS Input Voltage:
$cpp_involts
"
echo
"CPP UPS Runtime:
$cpp_runtime
"
}
write_data
()
{
#Write the data to the database
curl
-i
-XPOST
'http://localhost:8086/write?db=home'
--data-binary
"ups_data,host=synology,sensor=battvoltage value=
$syno_battvoltage
"
...
...
@@ -65,13 +101,24 @@ write_data () {
curl
-i
-XPOST
'http://localhost:8086/write?db=home'
--data-binary
"ups_data,host=synology,sensor=runtime value=
$syno_runtime
"
}
write_data_cpp
()
{
#Finally we can write it to the database
curl
-i
-XPOST
'http://localhost:8086/write?db=home'
--data-binary
"ups_data,host=host1,sensor=battvoltage denhost1.value=
$cpp_battvolts
"
curl
-i
-XPOST
'http://localhost:8086/write?db=home'
--data-binary
"ups_data,host=host1,sensor=battcharge denhost1.value=
$cpp_capacity
"
curl
-i
-XPOST
'http://localhost:8086/write?db=home'
--data-binary
"ups_data,host=host1,sensor=battload denhost1.value=
$cpp_loadpercent
"
curl
-i
-XPOST
'http://localhost:8086/write?db=home'
--data-binary
"ups_data,host=host1,sensor=battloadwatt denhost1.value=
$cpp_loadwatt
"
curl
-i
-XPOST
'http://localhost:8086/write?db=home'
--data-binary
"ups_data,host=host1,sensor=inputvoltage denhost1.value=
$cpp_involts
"
curl
-i
-XPOST
'http://localhost:8086/write?db=home'
--data-binary
"ups_data,host=host1,sensor=runtime denhost1.value=
$cpp_runtime
"
}
#Prepare to start the loop and warn the user
echo
"Press [CTRL+C] to stop..."
while
:
do
get_ups_info
get_ups_info_cpp
if
[[
$syno_battvoltage
-le
0
||
$syno_battcharge
-le
0
||
$syno_battload
-le
0
||
$syno_inputvoltage
-le
0
||
$syno_runtime
-le
0
]]
;
then
echo
"Skip this datapoint - something went wrong with the read"
...
...
@@ -82,6 +129,15 @@ do
write_data
fi
if
[[
$cpp_battvolts
-le
0
||
$cpp_capacity
-le
0
||
$cpp_loadpercent
-le
0
||
$cpp_involts
-le
0
||
$cpp_runtime
-le
0
]]
;
then
echo
"Skip this datapoint - something went wrong with the read"
else
#Output console data for future reference
print_data_cpp
write_data_cpp
fi
#Sleep between readings
sleep
"
$sleeptime
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment