Skip to content

Commit

Permalink
Merge pull request #16 from Uninett/feature/timeout
Browse files Browse the repository at this point in the history
Support for configuring API request timeout values in `navargus.yml`
  • Loading branch information
lunkwill42 authored Sep 1, 2023
2 parents a396b9c + 6ac7867 commit 820d75b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Notable changes to the library will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- Support for configuring API request timeout values in `navargus.yml`

## [0.6.6] - 2023-03-13

### Fixed
Expand Down
3 changes: 3 additions & 0 deletions navargus.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ api:
url: https://argus.example.org/api/v1
token: very-long-and-secret-string

# Timeout defaults to 2.0 seconds, but may be to small in some production settings
# timeout: 2.0

# If set to true, this ensures state differences between NAV alerts and Argus
# Incidents are synchronized before navargus begins reading new alerts from
# stdin
Expand Down
8 changes: 6 additions & 2 deletions src/navargus/glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

_logger = logging.getLogger("navargus")
_client = None
_config = None # type: Configuration
_config: "Configuration" = None
NOT_WHITESPACE = re.compile(r"[^\s]")
NAV_SERIES = tuple(int(i) for i in _NAV_VERSION.split(".")[:2])
NAV_VERSION_WITH_SEVERITY = (5, 2)
Expand Down Expand Up @@ -356,7 +356,7 @@ def get_argus_client():
global _client
if not _client:
_client = Client(
api_root_url=_config.get_api_url(), token=_config.get_api_token()
api_root_url=_config.get_api_url(), token=_config.get_api_token(), timeout=_config.get_api_timeout()
)
return _client

Expand Down Expand Up @@ -555,6 +555,10 @@ def get_api_token(self):
"""Returns the configured Argus API access token"""
return self.get("api", {}).get("token")

def get_api_timeout(self) -> float:
"""Returns the configured API request timeout value"""
return float(self.get("api", {}).get("timeout", 2.0))

def get_sync_on_startup(self):
"""Returns True if this program should always sync the Argus API on startup"""
return bool(self.get("api", {}).get("sync-on-startup"))
Expand Down

0 comments on commit 820d75b

Please sign in to comment.