-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[aix][host]: Uptime might have a comma #1867
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
base: master
Are you sure you want to change the base?
Conversation
|
@Dylan-M sorry to late fix. But could you check this PR is actually you want? Thanks! |
| var days, hours, mins uint64 | ||
| var err error | ||
|
|
||
| switch ut[3] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about using this :
func clearTime(ut string) string {
return strings.TrimRight(strings.TrimRight(ut, ","),"s")
}So you just switch on singular words for "day" or "hr" or "min" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also agree with this, but it can get messy when ut[5] and ut[7] may or may not exist (you cannot trim them ahead of time).
I don't agree with the function name though. "clearTime" makes it seem like you're removing the time, rather than just trimming a string on the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's just a suggestion, everything can be changed. The main goal is to decouple the cleaning of comma and s and then look for the type of time
| } | ||
| } | ||
| case "hr,", "hrs,": | ||
| case "hr,", "hrs,", "hr", "hrs": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case also needs a subcase for mins to be in ut[5], with appropriate protections.
| // day provided along with a single hour or hours | ||
| // ie: up 2 days, 20 hrs, | ||
| if ut[5] == "hr," || ut[5] == "hrs," { | ||
| if ut[5] == "hr," || ut[5] == "hrs," || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a subhandling for mins to be in ut[7], for a case where you have 20 days, 17 hrs, 5 mins
it all of these ifs should likely be exists/nil protected as well, since these array elements will only exist if the returned value previously has enough elements to fill it out this far.
Also both of these if ut[5] should probably be another switch/case statement for consistency.
| var days, hours, mins uint64 | ||
| var err error | ||
|
|
||
| switch ut[3] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also agree with this, but it can get messy when ut[5] and ut[7] may or may not exist (you cannot trim them ahead of time).
I don't agree with the function name though. "clearTime" makes it seem like you're removing the time, rather than just trimming a string on the time.
|
@Dylan-M Could you provide these uptime examples like in the test? I want to add those to the test.
|
I can't provide them easily, because it requires getting the system that shows those formats - since they only show when they're non-zero. Also, to further complicate it, one of my systems outputs uptime like this: Which is for less than a full day, but doesn't split it hrs and mins like I expected. I'll check back once it has been running > 24 hours to see what that looks like. I really hate the way AIX does uptime 😂 |
Here is what I have recorded (well, partial, I'm recording to a file every 15 minutes using a cronjob) And from later, another day crossing: |
|
@Dylan-M Thank you for the additional information. This is more complex than I expected. I’m starting to feel that a proper fix might be better than a quick workaround. It might be better to make use of regular expressions. I'm a busy for these days, so it might take me some time, but I’ll give it a try. Alternatively, feel free to send a good update yourself if you’d like! |
I'm sure one of us will get to it when we have time. I'm swamped with my day job work right now too. |
|
I think I've found a much better approach than the uptime command (and it's poorly machine readable format): Get the start time of the init process (pid 1) Here is the man page info for the This should be significantly easier to parse. |
|
My above solution using |
|
We can also pipe to fgrep to remove the ELPASED header more efficiently than we can probably do in Golang code. |
|
Looking at this: https://www.ibm.com/docs/en/aix/7.3.0?topic=p-ps-command It does seem that (On Linux, there's a |
|
Circling back to this (AIX work in this library in general) next week. I'll handle fixing this as part of that. As for |
#1809 accidentally introduced some of bug on AIX. (see this comment)
This PR fixes it and add
,to all of other symbols.Note: I don't have a AIX machine, so I can not check this works or not.