Convert enabled
for Client, Probe to use datetime instead of boolean
value is null if disabled, else timestamp of when it was last enabled
This commit is contained in:
parent
c45baaed5e
commit
f31a0c4c22
|
@ -0,0 +1,80 @@
|
|||
# -*- coding: utf-8; -*-
|
||||
"""make enabled datetime
|
||||
|
||||
Revision ID: fd1df160539a
|
||||
Revises: a2676d3dfc1e
|
||||
Create Date: 2019-01-25 18:41:01.652823
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import unicode_literals, absolute_import
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'fd1df160539a'
|
||||
down_revision = 'a2676d3dfc1e'
|
||||
branch_labels = None
|
||||
depends_on = None
|
||||
|
||||
import datetime
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
import rattail.db.types
|
||||
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
||||
now = datetime.datetime.utcnow()
|
||||
|
||||
# client
|
||||
op.add_column('client', sa.Column('new_enabled', sa.DateTime(), nullable=True))
|
||||
client = sa.sql.table('client',
|
||||
sa.sql.column('enabled'),
|
||||
sa.sql.column('new_enabled'))
|
||||
op.execute(client.update()\
|
||||
.where(client.c.enabled == True)\
|
||||
.values({'new_enabled': now}))
|
||||
op.drop_column('client', 'enabled')
|
||||
op.alter_column('client', 'new_enabled', new_column_name='enabled')
|
||||
|
||||
# probe
|
||||
op.add_column('probe', sa.Column('new_enabled', sa.DateTime(), nullable=True))
|
||||
probe = sa.sql.table('probe',
|
||||
sa.sql.column('enabled'),
|
||||
sa.sql.column('new_enabled'))
|
||||
op.execute(probe.update()\
|
||||
.where(probe.c.enabled == True)\
|
||||
.values({'new_enabled': now}))
|
||||
op.drop_column('probe', 'enabled')
|
||||
op.alter_column('probe', 'new_enabled', new_column_name='enabled')
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
# probe
|
||||
op.add_column('probe', sa.Column('old_enabled', sa.Boolean(), nullable=True))
|
||||
probe = sa.sql.table('probe',
|
||||
sa.sql.column('enabled'),
|
||||
sa.sql.column('old_enabled'))
|
||||
op.execute(probe.update()\
|
||||
.where(probe.c.enabled != None)\
|
||||
.values({'old_enabled': True}))
|
||||
op.execute(probe.update()\
|
||||
.where(probe.c.enabled == None)\
|
||||
.values({'old_enabled': False}))
|
||||
op.drop_column('probe', 'enabled')
|
||||
op.alter_column('probe', 'old_enabled', new_column_name='enabled', nullable=False)
|
||||
|
||||
# client
|
||||
op.add_column('client', sa.Column('old_enabled', sa.Boolean(), nullable=True))
|
||||
client = sa.sql.table('client',
|
||||
sa.sql.column('enabled'),
|
||||
sa.sql.column('old_enabled'))
|
||||
op.execute(client.update()\
|
||||
.where(client.c.enabled != None)\
|
||||
.values({'old_enabled': True}))
|
||||
op.execute(client.update()\
|
||||
.where(client.c.enabled == None)\
|
||||
.values({'old_enabled': False}))
|
||||
op.drop_column('client', 'enabled')
|
||||
op.alter_column('client', 'old_enabled', new_column_name='enabled', nullable=False)
|
|
@ -111,11 +111,11 @@ class Client(Base):
|
|||
Any arbitrary notes for the client.
|
||||
""")
|
||||
|
||||
enabled = sa.Column(sa.Boolean(), nullable=False, default=False, doc="""
|
||||
Whether the client should be considered enabled (active). If set, the
|
||||
client will be expected to take readings (but only for "enabled" probes)
|
||||
and the server will monitor them to ensure they are within the expected
|
||||
range etc.
|
||||
enabled = sa.Column(sa.DateTime(), nullable=True, doc="""
|
||||
This will either be the date/time when the client was most recently
|
||||
enabled, or null if it is not currently enabled. If set, the client will
|
||||
be expected to take readings (but only for "enabled" probes) and the server
|
||||
will monitor them to ensure they are within the expected range etc.
|
||||
""")
|
||||
|
||||
online = sa.Column(sa.Boolean(), nullable=False, default=False, doc="""
|
||||
|
@ -191,7 +191,13 @@ class Probe(Base):
|
|||
""")
|
||||
|
||||
device_path = sa.Column(sa.String(length=255), nullable=True)
|
||||
enabled = sa.Column(sa.Boolean(), nullable=False, default=True)
|
||||
|
||||
enabled = sa.Column(sa.DateTime(), nullable=True, doc="""
|
||||
This will either be the date/time when the probe was most recently enabled,
|
||||
or null if it is not currently enabled. If set, the client will be
|
||||
expected to take readings for this probe, and the server will monitor them
|
||||
to ensure they are within the expected range etc.
|
||||
""")
|
||||
|
||||
critical_temp_max = sa.Column(sa.Integer(), nullable=False, doc="""
|
||||
Maximum high temperature; when a reading is greater than or equal to this
|
||||
|
|
|
@ -37,13 +37,13 @@ def disabled_probes(config, progress=None):
|
|||
tempmon_session = TempmonSession()
|
||||
clients = tempmon_session.query(tempmon.Client)\
|
||||
.filter(tempmon.Client.archived == False)\
|
||||
.filter(tempmon.Client.enabled == False)\
|
||||
.filter(tempmon.Client.enabled == None)\
|
||||
.all()
|
||||
probes = tempmon_session.query(tempmon.Probe)\
|
||||
.join(tempmon.Client)\
|
||||
.filter(tempmon.Client.archived == False)\
|
||||
.filter(tempmon.Client.enabled == True)\
|
||||
.filter(tempmon.Probe.enabled == False)\
|
||||
.filter(tempmon.Client.enabled != None)\
|
||||
.filter(tempmon.Probe.enabled == None)\
|
||||
.all()
|
||||
if clients or probes:
|
||||
send_email(config, 'tempmon_disabled_probes', {
|
||||
|
|
|
@ -71,7 +71,7 @@ class TempmonServerDaemon(Daemon):
|
|||
|
||||
try:
|
||||
clients = session.query(tempmon.Client)\
|
||||
.filter(tempmon.Client.enabled == True)\
|
||||
.filter(tempmon.Client.enabled != None)\
|
||||
.filter(tempmon.Client.archived == False)
|
||||
for client in clients:
|
||||
self.check_readings_for_client(session, client)
|
||||
|
|
Loading…
Reference in a new issue