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

Add support for parsing performance data #175

Closed
atc0005 opened this issue Dec 16, 2022 · 0 comments · Fixed by #188
Closed

Add support for parsing performance data #175

atc0005 opened this issue Dec 16, 2022 · 0 comments · Fixed by #188
Assignees
Labels
enhancement New feature or request performance data
Milestone

Comments

@atc0005
Copy link
Owner

atc0005 commented Dec 16, 2022

Overview

This library already supports generating performance data metrics, now I wish to add support for reading/parsing performance data emitted by plugins.

The intent is to use this new functionality when parsing JSON responses from the Nagios XI API, specifically GET objects/servicestatus.

Example JSON response from GET request
{
    "recordcount": 1,
    "servicestatus": [
        {
            "host_name": "localhost",
            "service_description": "Current Load",
            "display_name": "Current Load",
            "host_object_id": "145",
            "host_address": "127.0.0.1",
            "host_alias": "localhost",
            "icon_image": "",
            "icon_image_alt": "",
            "notes": "Testing 123",
            "notes_url": "",
            "action_url": "",
            "servicestatus_id": "21",
            "instance_id": "1",
            "service_object_id": "157",
            "status_update_time": "2020-04-06 14:16:30",
            "output": "OK - load average: 0.26, 0.32, 0.30",
            "long_output": "",
            "perfdata": "load1=0.260;5.000;10.000;0; load5=0.320;4.000;6.000;0; load15=0.300;3.000;4.000;0;",
            "current_state": "0",
            "has_been_checked": "1",
            "should_be_scheduled": "1",
            "current_check_attempt": "1",
            "max_check_attempts": "4",
            "last_check": "2020-04-06 14:16:30",
            "next_check": "2020-04-06 14:21:30",
            "check_type": "0",
            "check_options": "0",
            "last_state_change": "2020-02-01 16:10:38",
            "last_hard_state_change": "2020-02-01 16:10:38",
            "last_hard_state": "0",
            "last_time_ok": "2020-04-06 14:16:30",
            "last_time_warning": "1969-12-31 18:00:00",
            "last_time_unknown": "1969-12-31 18:00:00",
            "last_time_critical": "1969-12-31 18:00:00",
            "state_type": "1",
            "last_notification": "1969-12-31 18:00:00",
            "next_notification": "1969-12-31 18:00:00",
            "no_more_notifications": "0",
            "notifications_enabled": "1",
            "problem_has_been_acknowledged": "0",
            "acknowledgement_type": "0",
            "current_notification_number": "0",
            "passive_checks_enabled": "1",
            "active_checks_enabled": "1",
            "event_handler_enabled": "1",
            "flap_detection_enabled": "1",
            "is_flapping": "0",
            "percent_state_change": "0",
            "latency": "0.00219999998807907",
            "execution_time": "0.00254",
            "scheduled_downtime_depth": "0",
            "failure_prediction_enabled": "0",
            "process_performance_data": "1",
            "obsess_over_service": "1",
            "modified_service_attributes": "0",
            "event_handler": "",
            "check_command": "check_local_load!5.0,4.0,3.0!10.0,6.0,4.0\\!test!!!!!!",
            "normal_check_interval": "5",
            "retry_check_interval": "1",
            "check_timeperiod_object_id": "129"
        }
    ]
}

Example input

Example strings that this new functionality should be able to parse are included below (and should be further represented by sufficient test cases).

  • "load1=0.260;5.000;10.000;0; load5=0.320;4.000;6.000;0; load15=0.300;3.000;4.000;0;"
  • load1=0.260;5.000;10.000;0; load5=0.320;4.000;6.000;0; load15=0.300;3.000;4.000;0;
  • 'time'=49ms;;;;
    • of note are the single quotes around the label
  • /=7826MB;28621;30211;0;31802 /dev/shm=0MB;3542;3739;0;3936 /boot=40MB;428;452;0;476

References

@atc0005 atc0005 added enhancement New feature or request performance data labels Dec 16, 2022
@atc0005 atc0005 added this to the Future milestone Dec 16, 2022
@atc0005 atc0005 self-assigned this Dec 16, 2022
atc0005 added a commit that referenced this issue Jan 26, 2023
Minor changes applied as a follow-up to PR #178:

- concentrate new Range functionality in dedicated files
  - this reflects similar work underway for GH-175
- update README
  - mention new Range support
  - link to dependent projects (including one from contributor
    of new functionality)
- doc comment tweaks
- misc changes to satisfy current CI linters

Credit for original work:

- @infraweavers (https://github.com/infraweavers)
- #178

refs GH-176
refs GH-178
atc0005 added a commit that referenced this issue Jan 26, 2023
Test began failing with work on PR branch for PR-175 which
expanded validation support for PerformanceData field values.

The previous test metric values used words in place of expected
field values:

- literal "U"
- character or values in the regex character class "[-0-9.]"

This commit moves the self-documenting Value field strings to
slice element comments and replaces them with placeholder
numeric values which pass Value field validation.

refs GH-175
atc0005 added a commit that referenced this issue Jan 27, 2023
- split performance data related code to separate files
- add new `ParsePerfData` function to parse a performance data metric
  string (as emitted by plugins) as `PerformanceData` values
- add "should succeed" and "should fail" table tests for
  `ParsePerfData` function
- add validation support for `PerformanceData` field values
  - used by `ParsePerfData`
  - planned use with `(nagios.PerformanceData).Validate`
- update README to list new performance data metric string parsing
  support

refs GH-175
atc0005 added a commit that referenced this issue Jan 27, 2023
- split performance data related code to separate files
- add new `ParsePerfData` function to parse a performance data metric
  string (as emitted by plugins) as `PerformanceData` values
- add "should succeed" and "should fail" table tests for
  `ParsePerfData` function
- add validation support for `PerformanceData` field values
  - used by `ParsePerfData`
  - planned use with `(nagios.PerformanceData).Validate`
- update README to list new performance data metric string parsing
  support

refs GH-175
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance data
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant