aru
Regular Contributor
I've discovered another interesting application: enlisting the robot's help to analysis logs for abnormalities. Friends who are interested can give it a try.
Upon entering http://router.asus.com/user19.asp in the browser, the displayed results are as follows:
The following software packages are pre-installed in cmdline:
Python app
Get API key from https://aistudio.google.com/app/apikey
Create the directory /jffs/addons/myaddon and the script user19.py inside:
Please paste the following script:
You may need to manually adjust the following user19.py script as indicated in red according to your router environment:
Change the file permissions of user19.py to make it executable.
Then, execute the /jffs/addons/myaddon/user19.py file in cmdline. The output will be as follows:
How to mount your own webpage onto the router menu steps as below:
Edit the /tmp/menuTree.js file
Search for the following crucial keywords highlighted in red. You'll notice that all other addon menus are uniformly integrated here (as indicated in blue).
You simply need to insert your own link in a single line (as shown in green).
After editing, simply remount the menu using the following cmdline to complete the process.
Done!
Note: I am currently unable to confirm whether Google Generative AI has free query restrictions. This may depend on the specific API you are using, as well as the quotas and usage associated with your API key. It is recommended to consult the official documentation of Google Generative AI or contact the Google support team for detailed information and restrictions regarding the API. Typically, major AI service providers may implement some form of quotas or restrictions to manage usage and resource allocation.
Upon entering http://router.asus.com/user19.asp in the browser, the displayed results are as follows:
Question:
Please analyze whether the following log content has any issues:
Messages Log Content:
ted
Mar 25 09:30:14 GT-AX6000-0FC8 hostapd: eth7: STA 8a:3b:8c:ef:75:c2 RADIUS: starting accounting session 07A303C67E996661
Mar 25 09:30:14 GT-AX6000-0FC8 hostapd: eth7: STA 8a:3b:8c:ef:75:c2 WPA: pairwise key handshake completed (RSN)
Mar 25 09:44:35 GT-AX6000-0FC8 hostapd: eth6: STA f0:2f:74:8f:93:81 WPA: group key handshake completed (RSN)
Mar 25 09:44:35 GT-AX6000-0FC8 hostapd: eth6: STA f0:2f:74:fd:65:11 WPA: group key handshake completed (RSN)
Mar 25 09:44:35 GT-AX6000-0FC8 hostapd: eth6: STA 10:5a:17:e5:63:60 WPA: group key handshake completed (RSN)
Mar 25 09:44:35 GT-AX6000-0FC8 hostapd: eth6: STA 1c:90:ff:e7:38:24 WPA: group key handshake completed (RSN)
Mar 25 09:44:39 GT-AX6000-0FC8 hostapd: eth7: STA f0:2f:74:fd:65:18 WPA: group key handshake completed (RSN)
Mar 25 09:44:39 GT-AX6000-0FC8 hostapd: eth7: STA f0:2f:74:8f:93:88 WPA: group key handshake completed (RSN)
Mar 25 09:44:39 GT-AX6000-0FC8 hostapd: eth7: STA 8a:3b:8c:ef:75:c2 WPA: group key handshake completed (RSN)
GenAI Analysis Result:
There are no significant issues in the provided log content. The logs show successful RADIUS accounting session initiation, WPA pairwise and group key handshake completions for multiple stations on different interfaces (eth6 and eth7). These events indicate normal Wi-Fi client connection and authentication processes.
The following software packages are pre-installed in cmdline:
Python app
#opkg install python3
#opkg install python3-pip
#pip install google-generativeai
Get API key from https://aistudio.google.com/app/apikey
Create the directory /jffs/addons/myaddon and the script user19.py inside:
#mkdir /jffs/addons/myaddon
#nano -w /jffs/addons/myaddon/user19.py
Please paste the following script:
Code:
#!/tmp/mnt/usbkey/entware/bin/python
import os
import requests
import google.generativeai as genai
# Read the latest 10000 characters of the message log
log_file_path = '/mnt/usbkey/entware/var/log/messages'
num_chars = 10000
with open(log_file_path, 'r') as file:
file.seek(0, os.SEEK_END) # Move to the end of the file
end_position = file.tell()
start_position = max(0, end_position - num_chars) # Ensure not to exceed the file's range
file.seek(start_position)
log_content = file.read()
# Use Google's Generative AI for analysis
api_key = 'Your API key' # Replace this with your API key
genai.configure(api_key=api_key)
model = genai.GenerativeModel('gemini-pro')
# First, ask a question
question = 'Please analyze whether the following log content has any issues:'
response = model.generate_content(question + '\n' + log_content)
genai_result = response.text
# Save the log content and analysis result to a file
output_file_path = '/tmp/var/wwwext/user19.asp'
with open(output_file_path, 'w') as output_file:
output_file.write('<html><body>')
output_file.write('<h2>Question:</h2>')
output_file.write('<pre>{}</pre>'.format(question))
output_file.write('<h2>Messages Log Content:</h2>')
output_file.write('<pre>{}</pre>'.format(log_content))
output_file.write('<h2>GenAI Analysis Result:</h2>')
output_file.write('<pre>{}</pre>'.format(genai_result))
output_file.write('</body></html>')
print('Question, Log content, and GenAI analysis result saved to', output_file_path)
You may need to manually adjust the following user19.py script as indicated in red according to your router environment:
#!/tmp/mnt/usbkey/entware/bin/python
.
api_key = 'Your API key' # Replace this with your API key
.
mymap.save("/tmp/var/wwwext/user19.asp")
Change the file permissions of user19.py to make it executable.
#chmod 775 /jffs/addons/myaddon/user19.py
Then, execute the /jffs/addons/myaddon/user19.py file in cmdline. The output will be as follows:
How to mount your own webpage onto the router menu steps as below:
Edit the /tmp/menuTree.js file
#nano -w /tmp/menuTree.js
Search for the following crucial keywords highlighted in red. You'll notice that all other addon menus are uniformly integrated here (as indicated in blue).
{
menuName: "Addons",
index: "menu_Addons",
tab: [
{url: "user20.asp", tabName: "Skynet-Maps"},
{url: "user2.asp", tabName: "Unbound"},
{url: "user3.asp", tabName: "dn-vnstat"},
{url: "user4.asp", tabName: "connmon"},
{url: "user5.asp", tabName: "ntpMerlin"},
{url: "user7.asp", tabName: "scMerlin"},
{url: "javascript:var helpwindow=window.open('/ext/shared-jy/redirect.htm','_bl>
{url: "user8.asp", tabName: "Sitemap"},
{url: "NULL", tabName: "__INHERIT__"}
]
}
You simply need to insert your own link in a single line (as shown in green).
{
menuName: "Addons",
index: "menu_Addons",
tab: [
{url: "user19.asp", tabName: "AI analyzes log"},
{url: "user20.asp", tabName: "Skynet-Maps"},
{url: "user2.asp", tabName: "Unbound"},
{url: "user3.asp", tabName: "dn-vnstat"},
{url: "user4.asp", tabName: "connmon"},
{url: "user5.asp", tabName: "ntpMerlin"},
{url: "user7.asp", tabName: "scMerlin"},
{url: "javascript:var helpwindow=window.open('/ext/shared-jy/redirect.htm','_bl>
{url: "user8.asp", tabName: "Sitemap"},
{url: "NULL", tabName: "__INHERIT__"}
]
}
After editing, simply remount the menu using the following cmdline to complete the process.
#umount /www/require/modules/menuTree.js && mount -o bind /tmp/menuTree.js /www/require/modules/menuTree.js
Done!
Note: I am currently unable to confirm whether Google Generative AI has free query restrictions. This may depend on the specific API you are using, as well as the quotas and usage associated with your API key. It is recommended to consult the official documentation of Google Generative AI or contact the Google support team for detailed information and restrictions regarding the API. Typically, major AI service providers may implement some form of quotas or restrictions to manage usage and resource allocation.
Last edited: