forked from coppit/unraid-snmp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update plugin to 2020.10.04 to add memory info and Settings page
- Loading branch information
Showing
11 changed files
with
151 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,12 +45,13 @@ The key to creating these Slackware packages is to use `makepkg` which is provid | |
|
||
|
||
|
||
* Get the source code from macOS onto Unraid with `scp -r ~/GitHub/kubedzero/unraid-snmp/source root@unraid.local:/tmp/packageSource` | ||
* recursively copy all source files to the Unraid server with IP `unraid.local` | ||
* replace `unraid.local` with `192.168.1.10` or whatever your server's IP is | ||
* Get the source code from macOS onto Unraid with `scp -r ~/GitHub/kubedzero/unraid-snmp/source root@unraid:/tmp/packageSource` | ||
* recursively copy all source files to the Unraid server with IP `unraid` | ||
* replace `unraid` with `192.168.1.10` or whatever your server's IP is | ||
* `scp` will automatically create the `packageSource` directory and drop the sub-contents into it. So if there was a file on macOS `~/GitHub/kubedzero/unraid-snmp/source/install/doinst.sh` it would be copied to `/tmp/packageSource/install/doinst.sh`. | ||
* Copy the `createpackage.sh` script as well: `scp ~/GitHub/kubedzero/unraid-snmp/createpackage.sh [email protected]:/tmp/` | ||
* Run a remote SSH command on macOS to build the package: `ssh -t [email protected] "cd /tmp/ && bash /tmp/createpackage.sh 2020.09.19 /tmp/packageSource/"` | ||
* NOTE: If `/tmp/packageSource` already existed before running the command, the `./source` directory is created within. So if there was a file on macOS `~/GitHub/kubedzero/unraid-snmp/source/install/doinst.sh` it would be copied to `/tmp/packageSource/source/install/doinst.sh`. | ||
* Copy the `createpackage.sh` script as well: `scp ~/GitHub/kubedzero/unraid-snmp/createpackage.sh root@unraid:/tmp/` | ||
* Run a remote SSH command on macOS to build the package: `ssh -t root@unraid "cd /tmp/ && bash /tmp/createpackage.sh 2020.09.19 /tmp/packageSource/"` | ||
* The `-t` command executes everything in the double quotes on the Unraid server | ||
* The command first establishes a location by moving into the `/tmp/` directory | ||
* It then calls `bash /tmp/createpackage.sh` because Unraid changed to not allow direct execution, aka just executing `/tmp/createpackage.sh` | ||
|
@@ -64,7 +65,7 @@ The key to creating these Slackware packages is to use `makepkg` which is provid | |
* The `makepkg` command bundles everything in the directory from where it was called into the package, so in preparation, the script moves to the source directory (provided as the second argument) | ||
* The `makepkg` command is invoked and the package is created (outside the source directory, as required by the tool) | ||
* The MD5 of the created package is computed and printed for convenience | ||
* Now we need to copy the compiled package back to macOS, where our Git repository lives. `scp "root@unraid.local:/tmp/*.txz" ~/GitHub/kubedzero/unraid-snmp/packages` | ||
* Now we need to copy the compiled package back to macOS, where our Git repository lives. `scp "root@unraid:/tmp/*.txz" ~/GitHub/kubedzero/unraid-snmp/packages` | ||
* This copies any `.txz` file in `/tmp/` so it doesn't have to be updated for version bumps, but `*.txz` can just as easily be replaced with the full name `unraid-snmp-2020.09.19-x86_64-1.txz` if desired | ||
* Now we need to update the MD5 listed in the `snmp.plg` file for the `unraid-snmp.txz` package we copied over. I do this manually, using the printout from the `createpackage.sh` script. A sample MD5 is `09655c2ee9391e64ff7584b2893b5454` | ||
* Now update the plugin version in the `snmp.plg` file if it hasn't already been done, commit the code and package changes, and push to GitHub | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/bash | ||
|
||
# This uses /proc/meminfo to grab various memory values for SNMP | ||
|
||
# https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/ | ||
set -euo pipefail | ||
|
||
# Given arguments, retrieve and format for output to SNMP | ||
# $1 is proc_mem_name_grep, $2 is friendly_name | ||
getValFromMemInfo () { | ||
|
||
# Using the passed in argument, try to get the line from /proc/meminfo | ||
mem_value=$(grep "$1" /proc/meminfo) | ||
|
||
# Skip outputting if grep pattern did not yield exactly one result | ||
if [[ ! "$(echo $mem_value | wc -l)" -eq "1" ]] | ||
then | ||
return | ||
fi | ||
|
||
# Comparing to free --kibi, kibibytes is confirmed in /proc/meminfo | ||
mem_value_kibi=$(echo "$mem_value" | awk '{print $2}') | ||
# Change to bytes, avoid kilobyte (1000 bytes) kibibyte (1024 bytes) misuse | ||
mem_value_bytes=$((mem_value_kibi * 1024)) | ||
# Use the friendly name and byte value as output | ||
echo "$2: $mem_value_bytes" | ||
} | ||
|
||
# Call the function, $1 is the grep pattern and $2 is the SNMP output name | ||
# https://access.redhat.com/solutions/406773 describes different values | ||
getValFromMemInfo "MemTotal:" "MemTotal" | ||
getValFromMemInfo "MemFree:" "MemFree" | ||
getValFromMemInfo "MemAvailable:" "MemAvailable" | ||
# Force matching at the beginning of the line | ||
getValFromMemInfo "^Cached:" "Cached" | ||
getValFromMemInfo "Active:" "Active" | ||
getValFromMemInfo "Inactive:" "Inactive" | ||
getValFromMemInfo "Committed_AS:" "Committed_AS" | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
Menu="Utilities" | ||
Icon="snmp.png" | ||
Title="SNMP" | ||
Tag="cogs" | ||
--- | ||
|
||
<!-- Menu is in what section of Unraid the page shows up. --> | ||
<!-- "Utilities" puts this page in Settings > User Utilities --> | ||
<!-- "Tools" puts this page in the Tools menu --> | ||
<!-- Icon can be the png in the /usr/local/emhttp/plugins/snmp dir --> | ||
<!-- Title is the name showing up on the Settings page / in the header --> | ||
<!-- Tag can be any Font Awesome icon name https://fontawesome.com/icons --> | ||
|
||
|
||
<? | ||
// Dynamix provided function to parse /boot/config/plugins/snmp/snmp.cfg | ||
// Sample line from .cfg: SETTINGNAME="value"; | ||
$cfg = parse_plugin_cfg('snmp'); | ||
?> | ||
|
||
<!-- Creates the settings form, which can POST updates to the server --> | ||
<!-- Configures reads/writes to the file /boot/config/plugins/snmp/snmp.cfg --> | ||
<form markdown="1" method="POST" action="/update.php" target="progressFrame"> | ||
<input type="hidden" name="#file" value="snmp/snmp.cfg"> | ||
|
||
<!-- Adds a new category to the Form --> | ||
<!-- The colon space moves it in the same line to the right --> | ||
<!-- Set the name to be used for storage in the file, plus the ID for javascript reference --> | ||
Enable Unsafe Temperature Checking: | ||
: <select name="UNSAFETEMP" id="unsafeTemp"> | ||
<!-- Create options for this category. It will try to grab the config value first, --> | ||
<!-- and then fall back to the first option for visibility --> | ||
<!-- 0/1 are the values written to the .cfg while No/Yes are shown in the UI --> | ||
<?=mk_option($cfg['UNSAFETEMP'], "0", "No") ?> | ||
<?=mk_option($cfg['UNSAFETEMP'], "1", "Yes") ?> | ||
</select> | ||
|
||
<!-- Popup help section that can be accessed by clicking on the category name --> | ||
> By default, this is disabled and SNMP only checks the disk temperature if the disk reports itself to be out of STANDBY mode. Some systems' disks always report STANDBY mode, preventing SNMP from ever fetching disk temperature. Enable this setting to use a less safe method of temperature fetching that may wake the disks from STANDBY in some systems. | ||
|
||
<!-- Create a button titled "Default" in the UI --> | ||
<!-- It calls setDefaults javascript function when clicked and then submits the form after--> | ||
<input type="submit" value="Default" onClick="setDefaults(this.form)"> | ||
<!-- Create a button titled "Apply" that submits the form --> | ||
: <input type="submit" value="Apply"> | ||
<!-- Button titled "Done" that calls done() and returns to the page before without submission --> | ||
<input type="button" value="Done" onclick="done()"> | ||
</form> | ||
|
||
|
||
<!-- Javascript block where we can define various JS code --> | ||
<!-- Create a function called setDefaults that resets the form values --> | ||
<!-- It finds form values by their ID --> | ||
<script type="text/javascript"> | ||
function setDefaults(form) { | ||
form.unsafeTemp.value = "0"; | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters