Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OPNSense widget #730

Merged
merged 6 commits into from
Dec 26, 2022
Merged

OPNSense widget #730

merged 6 commits into from
Dec 26, 2022

Conversation

Oupsman
Copy link
Contributor

@Oupsman Oupsman commented Dec 25, 2022

First working version of OPNsense widget. CPU and memory usage are not quite reliable yet.

@shamoon
Copy link
Collaborator

shamoon commented Dec 25, 2022

Cool. Why are cpu and memory unreliable? Regex matching in general isn’t the most reliable thing but sometimes unavoidable

@Oupsman
Copy link
Contributor Author

Oupsman commented Dec 25, 2022

Cool. Why are cpu and memory unreliable? Regex matching in general isn’t the most reliable thing but sometimes unavoidable

Well, CPU usage sometime displays "NaN" and I can't understand why. The memory usage displayed by the widget is not the same as in the dashboard. Values returned by the API call are not the same. I've asked why on the OPNsense forum. If I don't get any answer, I think I'll have to write a special proxy for OPNsense and call the widget API, which is not callable in API mode (you have to be logged on the firewall interface to call it).

EDIT : beside, I'm only using regex for isolate the uptime. To isolate the CPU and memory values, I'm using the split function. I can send you the JSON result of the API call if you want.

@shamoon
Copy link
Collaborator

shamoon commented Dec 25, 2022

Gotcha. In general we prefer widgets to not use their own proxy if possible, hugely reduces code maintenance, errors, etc

Once I figure out how to get one of these setup I can test and review

@Oupsman
Copy link
Contributor Author

Oupsman commented Dec 25, 2022

Gotcha. In general we prefer widgets to not use their own proxy if possible, hugely reduces code maintenance, errors, etc

That's what I thought and honestly, I would really prefer it without a proxy.js file. I've found the reason why the CPU value is unreliable, my split code is wrong : sometime, values are separated by two spaces, and sometime, not. So I think I'll use substr instead.

EDIT : it seems the substr function is deprecated so I'm using substring instead.

@shamoon shamoon linked an issue Dec 25, 2022 that may be closed by this pull request
Copy link
Collaborator

@shamoon shamoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall nice, works great.

I think the calculations are overkill, I would just change to using the statistics reported from the api.

I also think that 5 blocks gets pretty cramped (see below) so I would advocate for reducing this by at least 1. In fact I would say to remove the WAN data and then you can remove the second API call to keep things speedier. But up to you on that last point, I didnt include it in the suggestions.

Screen Shot 2022-12-25 at 2 58 15 PM

src/widgets/opnsense/component.jsx Outdated Show resolved Hide resolved
src/widgets/opnsense/component.jsx Outdated Show resolved Hide resolved
src/widgets/opnsense/component.jsx Outdated Show resolved Hide resolved
public/locales/en/common.json Outdated Show resolved Hide resolved
Copy link
Collaborator

@shamoon shamoon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple other random things

src/widgets/opnsense/component.jsx Outdated Show resolved Hide resolved
src/widgets/opnsense/widget.js Show resolved Hide resolved
@Oupsman
Copy link
Contributor Author

Oupsman commented Dec 26, 2022

I also think that 5 blocks gets pretty cramped (see below) so I would advocate for reducing this by at least 1. In fact I would say to remove the WAN data and then you can remove the second API call to keep things speedier. But up to you on that last point, I didnt include it in the suggestions.

That is the data requested in the enhancement request.

But I'm wondering if the uptime is really that important a data to see : if the firewall were to reboot, the WAN datas will be reset to zero at the reboot moment so you'll see a huge decrease on the widget.

@shamoon
Copy link
Collaborator

shamoon commented Dec 26, 2022

But I'm wondering if the uptime is really that important a data to see : if the firewall were to reboot, the WAN datas will be reset to zero at the reboot moment so you'll see a huge decrease on the widget.

Yea but as the widget author it’s really up to you :)

@shamoon
Copy link
Collaborator

shamoon commented Dec 26, 2022

Mate, you asked for feedback and are ignoring it even though you mentioned not being very comfortable with JS. We appreciate your contribution but please understand that part of the job here is to try and maintain consistent code quality.

The memory calc isnt working in my testing.

Screen Shot 2022-12-25 at 10 45 01 PM

Again, my suggestions are meant to simplify your code and make it less error-prone. Please adjust.

* OPNSense widget : initial version, memory usage is inaccurate.

* OPNSense widget : code cleanup in widget.js. Firewall is no longer displayed, so it did not need to be queried.
* OPNSense widget : initial version, memory usage is inaccurate.

* OPNSense widget : code cleanup in widget.js. Firewall is no longer displayed, so it did not need to be queried.

* OPNSense widget : fixing the CPU code to make it more reliable.

* OPNSense widget : fixing the CPU code to make it more reliable. Removing uptime info
@Oupsman
Copy link
Contributor Author

Oupsman commented Dec 26, 2022

Mate, you asked for feedback and are ignoring it even though you mentioned not being very comfortable with JS. We appreciate your contribution but please understand that part of the job here is to try and maintain consistent code quality.

The memory calc isnt working in my testing.

Screen Shot 2022-12-25 at 10 45 01 PM

Again, my suggestions are meant to simplify your code and make it less error-prone. Please adjust.

I am trying the regex to get the idle value right now. Sorry if you thought I'm not taking your advice into account, I'm trying to keep up with you, on the contrary.

@shamoon
Copy link
Collaborator

shamoon commented Dec 26, 2022

It was a code suggestion above, you can just apply suggestions using the GH site

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
@shamoon
Copy link
Collaborator

shamoon commented Dec 26, 2022

Let me know if youre still working on this (obviously if youre offline no worries)

@Oupsman
Copy link
Contributor Author

Oupsman commented Dec 26, 2022

Let me know if youre still working on this (obviously if youre offline no worries)

I have to work (holidays are over) but I think I'll work on it in the evening. As the memory code is really unreliable (as per your testings, I'm not the only one in this case) I think I'm going to drop it, because I think it's better to report no value than a unreliable value.

@shamoon
Copy link
Collaborator

shamoon commented Dec 26, 2022

Let me know if youre still working on this (obviously if youre offline no worries)

I have to work (holidays are over) but I think I'll work on it in the evening. As the memory code is really unreliable (as per your testings, I'm not the only one in this case) I think I'm going to drop it, because I think it's better to report no value than a unreliable value.

I agree. That change is also a suggestion here, if you dont mind we can apply and get this merged and done.

@Oupsman
Copy link
Contributor Author

Oupsman commented Dec 26, 2022

Let me know if youre still working on this (obviously if youre offline no worries)

I have to work (holidays are over) but I think I'll work on it in the evening. As the memory code is really unreliable (as per your testings, I'm not the only one in this case) I think I'm going to drop it, because I think it's better to report no value than a unreliable value.

I agree. That change is also a suggestion here, if you dont mind we can apply and get this merged and done.

If I understand correctly, your proposition is to report the active memory, and I don't think that's a meaningful value. I'm more into purely stopping to report memory usage until I have a reliable way to retrieve it.

@shamoon
Copy link
Collaborator

shamoon commented Dec 26, 2022

If I understand correctly, your proposition is to report the active memory, and I don't think that's a meaningful value. I'm more into purely stopping to report memory usage until I have a reliable way to retrieve it.

I mean, if you feel strongly OK, but I would think most people would find the active memory value more useful than nothing, no?

Oupsman and others added 2 commits December 26, 2022 09:27
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
@Oupsman
Copy link
Contributor Author

Oupsman commented Dec 26, 2022

If I understand correctly, your proposition is to report the active memory, and I don't think that's a meaningful value. I'm more into purely stopping to report memory usage until I have a reliable way to retrieve it.

I mean, if you feel strongly OK, but I would think most people would find the active memory value more useful than nothing, no?

That's a valid point, I've validated your commits.

@shamoon
Copy link
Collaborator

shamoon commented Dec 26, 2022

Cheers, thanks for all the effort

@shamoon shamoon merged commit 94f43b1 into gethomepage:main Dec 26, 2022
arcoast added a commit to arcoast/homepage-docs that referenced this pull request Mar 9, 2023
I've added more details so only the least required amount of privileges are given to use this widget and also removed the `uptime` field which is non-functional and [I can't see a reference to it in the code](https://github.com/benphelps/homepage/blob/main/src/widgets/opnsense/component.jsx#L23-L26), so I think it was a leftover from a conversation [here.](gethomepage/homepage#730 (comment))
shamoon pushed a commit to shalak/homepage-docs that referenced this pull request Mar 20, 2023
I've added more details so only the least required amount of privileges are given to use this widget and also removed the `uptime` field which is non-functional and [I can't see a reference to it in the code](https://github.com/benphelps/homepage/blob/main/src/widgets/opnsense/component.jsx#L23-L26), so I think it was a leftover from a conversation [here.](gethomepage/homepage#730 (comment))
Copy link
Contributor

github-actions bot commented Feb 6, 2024

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new discussion for related concerns.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] OPNsense Transfer rates/amounts
2 participants