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

refactor: Allow _perc and _current columns to be string for alert rules #8532

Merged
merged 2 commits into from Apr 14, 2018

Conversation

Projects
None yet
3 participants
@laf
Copy link
Member

laf commented Apr 9, 2018

DO NOT DELETE THIS TEXT

Please note

Please read this information carefully. You can run ./scripts/pre-commit.php to check your code before submitting.

Testers

If you would like to test this pull request then please run: ./scripts/github-apply <pr_id>, i.e ./scripts/github-apply 5926

Fixes: https://community.librenms.org/t/trouble-with-storage-in-new-alert-rules-format/3724

@murrant

This comment has been minimized.

Copy link
Member

murrant commented Apr 10, 2018

Why are you making this change? I'd prefer you make the change in the other part of the code, like where enum is handled.

@laf

This comment has been minimized.

Copy link
Member Author

laf commented Apr 10, 2018

It’s not for enum. It’s because currently these columns are restricted to integers but you need to also compare them to other columns.

@murrant

This comment has been minimized.

Copy link
Member

murrant commented Apr 13, 2018

I don't understand "It’s not for enum". I meant we need a standard way/place to define specific filter items. That we way we can customize them and make it extra nice. Right now there is only one custom thing, that is the enum one. I expect we will add more...

I don't like changing in that function as that muddies getColumnType().

How many fields would we compare that against? Could we just list the fields in a drop down?

@laf

This comment has been minimized.

Copy link
Member Author

laf commented Apr 13, 2018

Moving it to the enum section would be this:

diff --git a/LibreNMS/Alerting/QueryBuilderFilter.php b/LibreNMS/Alerting/QueryBuilderFilter.php
index c99402fb9..4aec75be1 100644
--- a/LibreNMS/Alerting/QueryBuilderFilter.php
+++ b/LibreNMS/Alerting/QueryBuilderFilter.php
@@ -101,7 +101,7 @@ class QueryBuilderFilter implements \JsonSerializable
                     continue;
                 }

-                $type = $this->getColumnType($column_type, $column);
+                $type = $this->getColumnType($column_type);

                 // ignore unsupported types (such as binary and blob)
                 if (is_null($type)) {
@@ -110,8 +110,12 @@ class QueryBuilderFilter implements \JsonSerializable

                 $field = "$table.$column";

-                // format enums as radios
-                if ($type == 'enum') {
+                if (ends_with($column, ['_perc', '_current'])) {
+                    $this->filter[$field] = [
+                        'id' => $field,
+                        'type' => 'string',
+                    ];
+                } elseif ($type == 'enum') {// format enums as radios
                     $values = explode(',', substr($column_type, 4));
                     $values = array_map(function ($val) {
                         return trim($val, "()' ");
@murrant

This comment has been minimized.

Copy link
Member

murrant commented Apr 14, 2018

Yes, I feel better with it in that place. But I do feel like we need a better way to handle "special cases".

I'd say put that here for now and we can maybe come up with something later if/when we add more.

@scrutinizer-notifier

This comment has been minimized.

Copy link

scrutinizer-notifier commented Apr 14, 2018

The inspection completed: 1 updated code elements

@laf laf merged commit 3db26c1 into librenms:master Apr 14, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
license/cla Contributor License Agreement is signed.
Details

TheMysteriousX added a commit to TheMysteriousX/librenms that referenced this pull request May 20, 2018

refactor: Allow _perc and _current columns to be string for alert rul…
…es (librenms#8532)

* refactor: Allow _perc and _current columns to be string for alert rules

* Moved the check for column type

@lock lock bot locked as resolved and limited conversation to collaborators Jun 13, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.