Created
June 7, 2021 13:30
-
-
Save Ashark/9a6a0c2af5b7c78e4acad7a07e96eb7e to your computer and use it in GitHub Desktop.
LibreNMS api workaround for https://github.com/librenms/librenms/issues/12607
This file contains hidden or 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
#!/bin/bash | |
# A crutch way to extract vlans from librenms, because currently (librenms 1.63) | |
# the api cannot provide all vlans, however the web interface can. | |
# See https://github.com/librenms/librenms/issues/12607 | |
pw="123456" | |
user="someuser" | |
url_to_login="https://yourdomain.com/login" | |
cookie_file="/tmp/yourdomain.com_cookies.txt" | |
function update_login() { | |
curl -k -s "$url_to_login" -b "$cookie_file" -c "$cookie_file" > /tmp/out_1.html # We need to get _token value from there | |
form_token=$(cat /tmp/out_1.html | grep "_token" | cut -f6 -d '"') | |
# echo "Extracted token: $form_token" | |
curl -k -s "$url_to_login" -L -b "$cookie_file" -c "$cookie_file" --data "_token=${form_token}&username=${user}&password=${pw}" > /dev/null # &remember | |
} | |
function extract_vlans() { | |
url="$1" | |
curl -k -s -L -b "$cookie_file" -c "$cookie_file" "$url" > /tmp/out.html | |
string=$(cat /tmp/out.html | grep -E "VLAN:|VLANs:") | |
# echo "$string" | |
if echo "$string" | grep "VLAN:" > /dev/null; then | |
# echo single | |
vlan_extracted=$(echo "$string" | sed 's/.*VLAN: \([0-9]*\)<.*/\1/' ) | |
elif echo "$string" | grep "VLANs:" > /dev/null; then | |
# echo multiple | |
vlan_extracted=$(echo "$string" | sed 's/.*title="\([0-9 ,]*\)".*/\1/') | |
fi | |
echo "$vlan_extracted" | |
} | |
if [[ "$1" == "-l" ]]; then | |
update_login | |
else | |
extract_vlans "$1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment