Project

General

Profile

Revision 1c5486c7

ID1c5486c7a3f269896ad00d1ba84e492f8d3ca8a9
Parent b5c06b88
Child c1f83918

Added by Francois POIROTTE about 5 years ago

[#1863] Timestamps en UTC

Change-Id: Idfa37670b4a6d97b60edea30d084e7b8f77f3d07
Refs: #1863

View differences:

vigiboard/controllers/feeds.py
25 25
        return {
26 26
            'feed': {
27 27
                'title': 'VigiBoard',
28
                'mtime': datetime.now(),
28
                'mtime': datetime.utcnow(),
29 29
            },
30 30
            'entries': [
31 31
                {
32 32
                    'title': 'Test',
33
                    'mtime': datetime.now(),
33
                    'mtime': datetime.utcnow(),
34 34
                    'summary': 'Foo bar on baz',
35 35
                }
36 36
            ],
vigiboard/controllers/plugins/date.py
40 40
        @rtype: C{unicode}
41 41
        """
42 42
        format = dateformat.get_date_format()
43
        date = datetime.strftime(datetime.now(), format).decode('utf-8')
43
        date = datetime.strftime(datetime.utcnow(), format).decode('utf-8')
44 44
        return _('Eg. %(date)s') % {'date': date}
45 45

  
46 46

  
......
90 90
                search['from_date'])
91 91

  
92 92
            # Ajout de contrôles sur la date de début
93
            if search['from_date'] >= datetime.now():
93
            if search['from_date'] >= datetime.utcnow():
94 94
                error_handler.handle_error_message(
95 95
                    _('Start date cannot be greater than current date'))
96 96

  
......
104 104
                search['to_date'])
105 105

  
106 106
            # Ajout de contrôles sur la date de fin
107
            if search['to_date'] >= datetime.now():
107
            if search['to_date'] >= datetime.utcnow():
108 108
                error_handler.handle_error_message(
109 109
                    _('End date cannot be greater than current date'))
110 110

  
......
115 115
        # On supprime les microsecondes qui ne nous apportent
116 116
        # aucune information et fausse l'affichage dans l'export CSV
117 117
        # en créant un nouvel objet timedelta dérivé du premier.
118
        duration = datetime.now() - event[0].timestamp_active
118
        duration = datetime.utcnow() - event[0].timestamp_active
119 119
        duration = timedelta(days=duration.days, seconds=duration.seconds)
120 120
        return {
121 121
            'state': state,
vigiboard/controllers/root.py
5 5

  
6 6
"""VigiBoard Controller"""
7 7

  
8
import calendar
8 9
import gettext
9 10
import os.path
10 11
from datetime import datetime
11
from time import mktime
12 12

  
13 13
from pkg_resources import resource_filename, working_set
14 14

  
......
222 222

  
223 223
        # Ajout des formulaires et préparation
224 224
        # des données pour ces formulaires.
225
        tmpl_context.last_modification = \
226
            mktime(get_last_modification_timestamp(ids_events).timetuple())
225
        tmpl_context.last_modification = calendar.timegm(
226
            get_last_modification_timestamp(ids_events).timetuple())
227 227

  
228 228
        tmpl_context.edit_event_form = EditEventForm("edit_event_form",
229 229
            submit_text=_('Apply'), action=url('/update'))
......
480 480
        # Ajout des formulaires et préparation
481 481
        # des données pour ces formulaires.
482 482
        ids_events = [event[0].idcause for event in page.items]
483
        tmpl_context.last_modification = \
484
            mktime(get_last_modification_timestamp(ids_events).timetuple())
483
        tmpl_context.last_modification = calendar.timegm(
484
            get_last_modification_timestamp(ids_events).timetuple())
485 485

  
486 486
        tmpl_context.edit_event_form = EditEventForm("edit_event_form",
487 487
            submit_text=_('Apply'), action=url('/update'))
......
569 569

  
570 570
        # Si des changements sont survenus depuis que la
571 571
        # page est affichée, on en informe l'utilisateur.
572
        last_modification = datetime.fromtimestamp(last_modification)
572
        last_modification = datetime.utcfromtimestamp(last_modification)
573 573
        cur_last_modification = get_last_modification_timestamp(idevents, None)
574 574
        if cur_last_modification and last_modification < cur_last_modification:
575 575
            flash(_('Changes have occurred since the page was last displayed, '
......
632 632
                            'to': trouble_ticket,
633 633
                        },
634 634
                        username=user.user_name,
635
                        timestamp=datetime.now(),
635
                        timestamp=datetime.utcnow(),
636 636
                    )
637 637
                DBSession.add(history)
638 638
                LOGGER.info(_('User "%(user)s" (%(address)s) changed the '
......
676 676
                            value=u'OK',
677 677
                            text="Forced state to 'OK'",
678 678
                            username=user.user_name,
679
                            timestamp=datetime.now(),
679
                            timestamp=datetime.utcnow(),
680 680
                            state=StateName.statename_to_value(u'OK'),
681 681
                        )
682 682
                    DBSession.add(history)
......
710 710
                            ack_label,
711 711
                        ),
712 712
                        username=user.user_name,
713
                        timestamp=datetime.now(),
713
                        timestamp=datetime.utcnow(),
714 714
                    )
715 715
                DBSession.add(history)
716 716
                LOGGER.info(_('User "%(user)s" (%(address)s) changed the state '
......
969 969
        return dict(groups=groups, items=[])
970 970

  
971 971
def get_last_modification_timestamp(event_id_list,
972
                                    value_if_none=datetime.now()):
972
                                    value_if_none=datetime.utcnow()):
973 973
    """
974 974
    Récupère le timestamp de la dernière modification
975 975
    opérée sur l'un des événements dont l'identifiant
......
988 988
            return None
989 989
        else:
990 990
            last_modification_timestamp = value_if_none
991
    return datetime.fromtimestamp(mktime(
992
        last_modification_timestamp.timetuple()))
991
    return datetime.utcfromtimestamp(calendar.timegm(
992
        last_modification_timestamp.utctimetuple()))
vigiboard/controllers/silence.py
424 424
        # les informations passées en paramètre
425 425
        silence.idsupitem = idsupitem
426 426
        silence.comment = comment
427
        silence.lastmodification = datetime.now().replace(microsecond=0)
427
        silence.lastmodification = datetime.utcnow().replace(microsecond=0)
428 428
        silence.author = user_name
429 429
        try:
430 430
            DBSession.add(silence)
vigiboard/tests/functional/plugins/test_details_plugin.py
28 28
        l'identifiant de l'L{Event} généré.
29 29
    @rtype: C{tuple}
30 30
    """
31
    timestamp = datetime.now()
31
    timestamp = datetime.utcnow()
32 32

  
33 33
    hostgroup = functions.add_supitemgroup(u'foo')
34 34
    host = functions.add_host(u'bar')
vigiboard/tests/functional/plugins/test_details_plugin_maps.py
105 105
    def _insert_dep(self):
106 106
        """Insertion de l'événement corrélé de test."""
107 107
        print("Insertion evenement correle")
108
        timestamp = datetime.now()
108
        timestamp = datetime.utcnow()
109 109
        supitem = DBSession.query(self.supitem_class).one()
110 110
        if isinstance(supitem, tables.Host):
111 111
            event = functions.add_event(supitem, u'DOWN', u'', timestamp)
vigiboard/tests/functional/test_history_table.py
58 58
    DBSession.add(EventHistory(
59 59
        type_action=u'Nagios update state',
60 60
        idevent=event.idevent,
61
        timestamp=datetime.now()))
61
        timestamp=datetime.utcnow()))
62 62
    DBSession.add(EventHistory(
63 63
        type_action=u'Acknowlegement change state',
64 64
        idevent=event.idevent,
65
        timestamp=datetime.now()))
65
        timestamp=datetime.utcnow()))
66 66
    DBSession.flush()
67 67

  
68 68
    functions.add_correvent([event])
vigiboard/tests/functional/test_raw_events_table.py
81 81
    DBSession.add(EventHistory(
82 82
        type_action=u'Nagios update state',
83 83
        idevent=event.idevent,
84
        timestamp=datetime.now()))
84
        timestamp=datetime.utcnow()))
85 85
    DBSession.add(EventHistory(
86 86
        type_action=u'Acknowlegement change state',
87 87
        idevent=event.idevent,
88
        timestamp=datetime.now()))
88
        timestamp=datetime.utcnow()))
89 89
    DBSession.flush()
90 90

  
91 91
    # Ajout d'un événement corrélé
vigiboard/tests/functional/test_root.py
15 15
"""
16 16
from nose.tools import assert_true, assert_false, assert_equal
17 17
from datetime import datetime
18
from time import mktime
18
from calendar import timegm
19 19
import transaction
20 20

  
21 21
from vigilo.models.session import DBSession
......
116 116
        (hosts, _services) = populate_DB()
117 117

  
118 118
        # On ajoute 2 évènements corrélés causés par ces hôtes
119
        timestamp = datetime.now()
119
        timestamp = datetime.utcnow()
120 120
        correvent1_id = add_correvent_caused_by(hosts[0], timestamp)
121 121
        correvent2_id = add_correvent_caused_by(hosts[1], timestamp)
122 122
        transaction.commit()
......
126 126
        response = self.app.post(
127 127
            '/update', {
128 128
                "id" : str(correvent1_id) + "," + str(correvent2_id),
129
                "last_modification": mktime(timestamp.timetuple()),
129
                "last_modification": timegm(timestamp.utctimetuple()),
130 130
                "trouble_ticket" : u"foo",
131 131
                "ack" : u'NoChange',
132 132
            }, status = 401)
......
143 143
                "id" : str(correvent1_id) + "," + str(correvent2_id),
144 144
                "ack" : u'NoChange',
145 145
                "trouble_ticket" : u"foo",
146
                "last_modification": mktime(timestamp.timetuple()),
146
                "last_modification": timegm(timestamp.utctimetuple()),
147 147
            }, status = 302, extra_environ = environ)
148 148

  
149 149
        response = response.follow(status=200, extra_environ = environ)
......
160 160
        response = self.app.post(
161 161
            '/update', {
162 162
                "id" : str(correvent1_id) + "," + str(correvent2_id),
163
                "last_modification": mktime(timestamp.timetuple()),
163
                "last_modification": timegm(timestamp.utctimetuple()),
164 164
                "trouble_ticket" : u"foo",
165 165
                "ack" : u'NoChange',
166 166
            }, status = 302, extra_environ = environ)
......
189 189
        (_hosts, services) = populate_DB()
190 190

  
191 191
        # On ajoute 2 évènements corrélés causés par ces hôtes
192
        timestamp = datetime.now()
192
        timestamp = datetime.utcnow()
193 193
        correvent1_id = add_correvent_caused_by(services[0], timestamp)
194 194
        correvent2_id = add_correvent_caused_by(services[1], timestamp)
195 195

  
......
200 200
        response = self.app.post(
201 201
            '/update', {
202 202
                "id" : str(correvent1_id) + "," + str(correvent2_id),
203
                "last_modification": mktime(timestamp.timetuple()),
203
                "last_modification": timegm(timestamp.utctimetuple()),
204 204
                "trouble_ticket" : u"foo",
205 205
                "ack" : u'NoChange',
206 206
            }, status = 401)
......
215 215
        response = self.app.post(
216 216
            '/update', {
217 217
                "id" : str(correvent1_id) + "," + str(correvent2_id),
218
                "last_modification": mktime(timestamp.timetuple()),
218
                "last_modification": timegm(timestamp.utctimetuple()),
219 219
                "trouble_ticket" : u"foo",
220 220
                "ack" : u'NoChange',
221 221
            }, status = 302, extra_environ = environ)
......
234 234
        response = self.app.post(
235 235
            '/update', {
236 236
                "id" : str(correvent1_id) + "," + str(correvent2_id),
237
                "last_modification": mktime(timestamp.timetuple()),
237
                "last_modification": timegm(timestamp.utctimetuple()),
238 238
                "trouble_ticket" : u"foo",
239 239
                "ack" : u'NoChange',
240 240
            }, status = 302, extra_environ = environ)
......
262 262
        (hosts, _services) = populate_DB()
263 263

  
264 264
        # On ajoute 2 évènements corrélés causés par ces hôtes
265
        timestamp = datetime.now()
265
        timestamp = datetime.utcnow()
266 266
        correvent1_id = add_correvent_caused_by(hosts[0], timestamp)
267 267
        correvent2_id = add_correvent_caused_by(hosts[1], timestamp)
268 268
        transaction.commit()
......
272 272
        response = self.app.post(
273 273
            '/update', {
274 274
                "id" : str(correvent1_id) + "," + str(correvent2_id),
275
                "last_modification": mktime(timestamp.timetuple()),
275
                "last_modification": timegm(timestamp.utctimetuple()),
276 276
                "trouble_ticket" : "",
277 277
                "ack" : u'Acknowledged',
278 278
            }, status = 401)
......
287 287
        response = self.app.post(
288 288
            '/update', {
289 289
                "id" : str(correvent1_id) + "," + str(correvent2_id),
290
                "last_modification": mktime(timestamp.timetuple()),
290
                "last_modification": timegm(timestamp.utctimetuple()),
291 291
                "trouble_ticket" : "",
292 292
                "ack" : u'Acknowledged',
293 293
            }, status = 302, extra_environ = environ)
......
306 306
        response = self.app.post(
307 307
            '/update', {
308 308
                "id" : str(correvent1_id) + "," + str(correvent2_id),
309
                "last_modification": mktime(timestamp.timetuple()),
309
                "last_modification": timegm(timestamp.utctimetuple()),
310 310
                "trouble_ticket" : "",
311 311
                "ack" : u'Acknowledged',
312 312
            }, status = 302, extra_environ = environ)
......
335 335
        (_hosts, services) = populate_DB()
336 336

  
337 337
        # On ajoute 2 évènements corrélés causés par ces hôtes
338
        timestamp = datetime.now()
338
        timestamp = datetime.utcnow()
339 339
        correvent1_id = add_correvent_caused_by(services[0], timestamp)
340 340
        correvent2_id = add_correvent_caused_by(services[1], timestamp)
341 341

  
......
346 346
        response = self.app.post(
347 347
            '/update', {
348 348
                "id" : str(correvent1_id) + "," + str(correvent2_id),
349
                "last_modification": mktime(timestamp.timetuple()),
349
                "last_modification": timegm(timestamp.utctimetuple()),
350 350
                "trouble_ticket" : "",
351 351
                "ack" : u'Acknowledged',
352 352
            }, status = 401)
......
361 361
        response = self.app.post(
362 362
            '/update', {
363 363
                "id" : str(correvent1_id) + "," + str(correvent2_id),
364
                "last_modification": mktime(timestamp.timetuple()),
364
                "last_modification": timegm(timestamp.utctimetuple()),
365 365
                "trouble_ticket" : "",
366 366
                "ack" : u'Acknowledged',
367 367
            }, status = 302, extra_environ = environ)
......
380 380
        response = self.app.post(
381 381
            '/update', {
382 382
                "id" : str(correvent1_id) + "," + str(correvent2_id),
383
                "last_modification": mktime(timestamp.timetuple()),
383
                "last_modification": timegm(timestamp.utctimetuple()),
384 384
                "trouble_ticket" : "",
385 385
                "ack" : u'Acknowledged',
386 386
            }, status = 302, extra_environ = environ)
......
408 408
        (_hosts, services) = populate_DB()
409 409

  
410 410
        # On ajoute 2 évènements corrélés causés par ces hôtes
411
        timestamp = datetime.now()
411
        timestamp = datetime.utcnow()
412 412
        correvent1_id = add_correvent_caused_by(services[0], timestamp)
413 413
        add_correvent_caused_by(services[1], timestamp)
414 414

  
415 415
        # Date de modification du premier évènement corrélé
416
        later_date = datetime.now()
416
        later_date = datetime.utcnow()
417 417
        # Date du chargement de la page
418
        date = mktime(later_date.timetuple()) - 42
418
        date = timegm(later_date.utctimetuple()) - 42
419 419

  
420 420
        # On ajoute une entrée dans l'historique de l'évènement brut
421 421
        # causant le premier évènement corrélé, portant pour timestamp
......
478 478
            )
479 479
            DBSession.add(host)
480 480
            DBSession.flush()
481
            add_correvent_caused_by(host, datetime.now())
481
            add_correvent_caused_by(host, datetime.utcnow())
482 482
        transaction.commit()
483 483

  
484 484
        environ = {'REMOTE_USER': 'manager'}
......
505 505
        response = self.app.post(
506 506
            '/update', {
507 507
                "id" : str(idcorrevent),
508
                "last_modification": mktime(datetime.now().timetuple()),
508
                "last_modification": timegm(datetime.utcnow().utctimetuple()),
509 509
                "trouble_ticket" : "",
510 510
                "ack" : u'Forced',
511 511
            }, status=302, extra_environ=environ)
vigiboard/tests/functional/test_search_form_host.py
18 18

  
19 19
def insert_deps():
20 20
    """Insère les dépendances nécessaires aux tests."""
21
    timestamp = datetime.now()
21
    timestamp = datetime.utcnow()
22 22

  
23 23
    hostgroup = SupItemGroup(name=u'foo', parent=None)
24 24
    DBSession.add(hostgroup)
vigiboard/tests/functional/test_search_form_misc.py
19 19

  
20 20
def insert_deps():
21 21
    """Insère les dépendances nécessaires aux tests."""
22
    timestamp = datetime.now() + timedelta(seconds=-10)
22
    timestamp = datetime.utcnow() + timedelta(seconds=-10)
23 23

  
24 24
    host = Host(
25 25
        name=u'bar',
......
146 146

  
147 147
        # Préparation des dates/heures.
148 148
        from_date = timestamp.strftime("%Y-%m-%d %I:%M:%S %p")
149
        to_date = datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
149
        to_date = datetime.utcnow().strftime("%Y-%m-%d %I:%M:%S %p")
150 150

  
151 151
        # Permet également de vérifier que la recherche
152 152
        # par date est inclusive.
......
173 173
        transaction.commit()
174 174

  
175 175
        # Préparation des dates/heures.
176
        from_date = datetime.now() + timedelta(seconds=60)
176
        from_date = datetime.utcnow() + timedelta(seconds=60)
177 177
        from_date = from_date.strftime("%Y-%m-%d %I:%M:%S %p")
178
        to_date = datetime.now().strftime("%Y-%m-%d %I:%M:%S %p")
178
        to_date = datetime.utcnow().strftime("%Y-%m-%d %I:%M:%S %p")
179 179

  
180 180
        # La recherche en utilisant une date de début supérieure
181 181
        # à la date actuelle doit générer une erreur/redirection.
......
201 201

  
202 202
        # Préparation des dates/heures.
203 203
        from_date = timestamp.strftime("%Y-%m-%d %I:%M:%S %p")
204
        to_date = datetime.now() + timedelta(seconds=60)
204
        to_date = datetime.utcnow() + timedelta(seconds=60)
205 205
        to_date = to_date.strftime("%Y-%m-%d %I:%M:%S %p")
206 206

  
207 207
        # La recherche en utilisant une date de fin supérieure
vigiboard/tests/functional/test_search_form_service.py
18 18

  
19 19
def insert_deps():
20 20
    """Insère les dépendances nécessaires aux tests."""
21
    timestamp = datetime.now()
21
    timestamp = datetime.utcnow()
22 22

  
23 23
    hostgroup = functions.add_supitemgroup(u'foo')
24 24
    host = functions.add_host(u'bar')

Also available in: Unified diff