This repository was archived by the owner on Mar 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Status checking #7
Open
laz2
wants to merge
3
commits into
matiaskorhonen:master
Choose a base branch
from
laz2:status-checking
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,4 +3,5 @@ pkg/* | |
| .bundle | ||
| .yardoc | ||
| doc/* | ||
| Gemfile.lock | ||
| Gemfile.lock | ||
| .idea/ | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| require "monit/constants" | ||
| require "monit/httpd" | ||
| require "monit/platform" | ||
| require "monit/server" | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Constants from monit sources: | ||
| # - monit.h | ||
| # - event.h | ||
| module Monit | ||
| MONITOR_NOT = 0 | ||
| MONITOR_YES = 1 | ||
| MONITOR_INIT = 2 | ||
| MONITOR_WAITING = 4 | ||
|
|
||
| MONITORMODE_ACTIVE = 0 | ||
| MONITORMODE_PASSIVE = 1 | ||
| MONITORMODE_MANUAL = 2 | ||
|
|
||
| PENDINGACTION_IGNORE = 0 | ||
| PENDINGACTION_ALERT = 1 | ||
| PENDINGACTION_RESTART = 2 | ||
| PENDINGACTION_STOP = 3 | ||
| PENDINGACTION_EXEC = 4 | ||
| PENDINGACTION_UNMONITOR = 5 | ||
| PENDINGACTION_START = 6 | ||
| PENDINGACTION_MONITOR = 7 | ||
|
|
||
| STATE_SUCCEEDED = 0 | ||
| STATE_FAILED = 1 | ||
| STATE_CHANGED = 2 | ||
| STATE_CHANGEDNOT = 3 | ||
| STATE_INIT = 4 | ||
|
|
||
| SERVICE_TYPE_FILESYSTEM = 0 | ||
| SERVICE_TYPE_DIRECTORY = 1 | ||
| SERVICE_TYPE_FILE = 2 | ||
| SERVICE_TYPE_PROCESS = 3 | ||
| SERVICE_TYPE_HOST = 4 | ||
| SERVICE_TYPE_SYSTEM = 5 | ||
| SERVICE_TYPE_FIFO = 6 | ||
| SERVICE_TYPE_PROGRAM = 7 | ||
|
|
||
| STATUS_CHECKSUM = 0x1 | ||
| STATUS_RESOURCE = 0x2 | ||
| STATUS_TIMEOUT = 0x4 | ||
| STATUS_TIMESTAMP = 0x8 | ||
| STATUS_SIZE = 0x10 | ||
| STATUS_CONNECTION = 0x20 | ||
| STATUS_PERMISSION = 0x40 | ||
| STATUS_UID = 0x80 | ||
| STATUS_GID = 0x100 | ||
| STATUS_NONEXIST = 0x200 | ||
| STATUS_INVALID = 0x400 | ||
| STATUS_DATA = 0x800 | ||
| STATUS_EXEC = 0x1000 | ||
| STATUS_FSFLAG = 0x2000 | ||
| STATUS_ICMP = 0x4000 | ||
| STATUS_CONTENT = 0x8000 | ||
| STATUS_INSTANCE = 0x10000 | ||
| STATUS_ACTION = 0x20000 | ||
| STATUS_PID = 0x40000 | ||
| STATUS_PPID = 0x80000 | ||
| STATUS_HEARTBEAT = 0x100000 | ||
| STATUS_STATUS = 0x200000 | ||
| STATUS_UPTIME = 0x40000 | ||
| end |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,16 @@ def do(action) | |
| end | ||
| end | ||
|
|
||
| def has_errors?(code = nil, exact = false) | ||
| if code.nil? or code == 0 | ||
| self.status.to_i != 0 and self.status_hint.to_i == 0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than converting
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may break interface for other users. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, but that's what SemVer is for right? I suppose it's up to the maintainer (if he's still active) whether or not he wants to introduce a breaking change. |
||
| elsif exact | ||
| self.status.to_i == code and self.status_hint.to_i == 0 | ||
| else | ||
| (self.status.to_i & code) != 0 and (self.status_hint.to_i & code) == 0 | ||
| end | ||
| end | ||
|
|
||
| private | ||
| # Renames the Service type from "type" to "service_type" to avoid conflicts | ||
| def rename_service_type(hash) | ||
|
|
||
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Seems like passing in
codeis done purely for testing purposes; it'd be better to not do so and instead find some other way to set the status, probably by mocking aServiceobject.Also I don't quite understand why
exactwas added; what's wrong with always being exact, or always being fuzzy?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.
Passing
codeto method allows error checking, because monit stores codes instatusand error flags instatus_hint.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'm confused, then; how does
codeallow error checking? Shouldn'thas_errors?already have all the information it needs between theServiceobject and the constants you've added?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.
Monit has many errors flags. Argument
codeallows testing of special error codes. If you callhas_errors?without arguments then it just determine presence of errors.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.
Ah I get it now, thanks for explaining.
I guess I prefer the ActiveRecord way of doing things.
.valid?doesn't let you assert against specific errors but rather only generally if there was an error. To check against specific errors, you have to check.errorsI suppose it's just personal preference, though.