# Graylog Alert set\_field to true or false if message in time range

**URL:** <https://community.graylog.org/t/graylog-alert-set-field-to-true-or-false-if-message-in-time-range/19820>\
**Category:** Graylog Central (peer support)\
**Created:** [May 12, 2021, 2:48pm UTC](https://community.graylog.org/t/graylog-alert-set-field-to-true-or-false-if-message-in-time-range/19820 "2021-05-12T14:48:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jupiter23](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@jupiter23](https://community.graylog.org/u/jupiter23)\
**Post date:** [May 12, 2021, 2:48pm UTC](https://community.graylog.org/t/graylog-alert-set-field-to-true-or-false-if-message-in-time-range/19820/1 "2021-05-12T14:48:03Z")

</div>

I’m trying to create an alert that only sends if messages are received between 2:00PM and 6:30PM.  
I’ve created this rule (some of my syntax might be incorrect, can ignore)

rule “function is\_trading”  
when  
has\_field(“timestamp”)  
then  
let msgTime = to\_string($message.timestamp.hourOfDay) + “:” + to\_string($message.timestamp.minuteOfHour)  
set\_field(“trading\_hours”, to\_string(“14:00” \<= msgTime \< “18:30”))  
end

Any thoughts on how to accomplish this would be much appreciated.

---

<div class="post-metadata">

**Author:** ![gsmith](https://sea2.discourse-cdn.com/flex016/user_avatar/community.graylog.org/gsmith/32/1222_2.png) [@gsmith](https://community.graylog.org/u/gsmith)\
**Post date:** [May 14, 2021, 12:02am UTC](https://community.graylog.org/t/graylog-alert-set-field-to-true-or-false-if-message-in-time-range/19820/2 "2021-05-14T00:02:55Z")

</div>

@jupiter23  
Hello and Welcome,

I think this might be what your looking for.  
I use this for users that login at a certain time. You probably can adjust it to fit your needs.

> <https://gist.github.com/jalogisch/72455fc830d6e0ab41f0c6aacb1c2bb9>

Hope that helps.

---

<div class="post-metadata">

**Author:** ![jupiter23](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@jupiter23](https://community.graylog.org/u/jupiter23)\
**Post date:** [May 14, 2021, 2:46pm UTC](https://community.graylog.org/t/graylog-alert-set-field-to-true-or-false-if-message-in-time-range/19820/3 "2021-05-14T14:46:22Z")

</div>

That’s great. Thank you, this is very helpful.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/graylog/original/3X/c/7/c7c09c6b5099570133d6502b83f50ba4430de5b6.png) [@system](https://community.graylog.org/u/system)\
**Post date:** [May 28, 2021, 2:46pm UTC](https://community.graylog.org/t/graylog-alert-set-field-to-true-or-false-if-message-in-time-range/19820/4 "2021-05-28T14:46:35Z")

</div>

Closed on May 28, 2021, 2:46pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
