-
Notifications
You must be signed in to change notification settings - Fork 187
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
RangeThreshold class pass float 0 to min or max bug #681
Labels
bug
Something isn't working
Comments
Hi @awesomeytj, Could you please share reproducible code? It would help us greatly to quickly fix this issue. Best regards |
import pandas as pd
from influxdb_client import InfluxDBClient
from django.conf import settings
from influxdb_client.domain.task_status_type import TaskStatusType
from influxdb_client.service.checks_service import ChecksService
from influxdb_client.domain.dashboard_query import DashboardQuery
from influxdb_client.domain.query_edit_mode import QueryEditMode
from influxdb_client.domain.threshold_check import ThresholdCheck
from influxdb_client.domain.lesser_threshold import LesserThreshold
from influxdb_client.domain.range_threshold import RangeThreshold
from influxdb_client.domain.greater_threshold import GreaterThreshold
from influxdb_client.domain.check_status_level import CheckStatusLevel
from influxdb_client.domain.http_notification_rule import HTTPNotificationRule
from influxdb_client.domain.task_status_type import TaskStatusType
from influxdb_client.domain.rule_status_level import RuleStatusLevel
from influxdb_client.domain.status_rule import StatusRule
from influxdb_client.service.notification_rules_service import NotificationRulesService
def activate_check():
try:
influxdb_client_obj = InfluxDBClient(url=settings.INFLUXDB_CONFIGS['URL'], token=settings.INFLUXDB_CONFIGS['TOKEN'], org=settings.INFLUXDB_CONFIGS['ORG_NAME'], debug=False)
influxdb_org_obj = influxdb_client_obj.organizations_api().find_organizations(org=settings.INFLUXDB_CONFIGS['ORG_NAME'])[0]
measurement = "device_temperature"
every = "5s"
threshold_level = 0
threshold_values = [0, 100]
bucket_name = settings.INFLUXDB_CONFIGS['BUCKET']
enum_map = {
0: CheckStatusLevel.OK,
1: CheckStatusLevel.INFO,
2: CheckStatusLevel.CRIT,
3: CheckStatusLevel.WARN,
}
if len(threshold_values) != 2:
return None
print(float(threshold_values[0]), float(threshold_values[1]))
threshold = RangeThreshold(level=enum_map[threshold_level], min=float(threshold_values[0]), max=float(threshold_values[1]), within=True)
query = f'''
from(bucket:"{bucket_name}")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "{measurement}")
|> filter(fn: (r) => r["device_code"] == "D00001")
|> filter(fn: (r) => r["_field"] == "reading")
|> last()
'''
check = ThresholdCheck(name=f"D00001_threshold_check_{measurement}_level_{threshold_level}",
status_message_template="The value is on: ${ r._level } level!",
every=every,
offset="0s",
query=DashboardQuery(edit_mode=QueryEditMode.ADVANCED, text=query),
thresholds=[threshold],
org_id=influxdb_org_obj.id,
status=TaskStatusType.ACTIVE)
checks_service = ChecksService(api_client=influxdb_client_obj.api_client)
check = checks_service.create_check(check)
check_info = {
"name": f"D00001_threshold_check_{measurement}_level_{threshold_level}",
"check_id": check.id,
}
return check_info
except Exception as e:
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Specifications
Code sample to reproduce problem
threshold = RangeThreshold(level=CheckStatusLevel.OK, min=0, max=10, within=True)
Expected behavior
raise ValueError: Invalid value for
min
, must not beNone
Actual behavior
use above code to create a check will raise error
Additional info
No response
The text was updated successfully, but these errors were encountered: