# Question: where are service.state and service.state\_id stored

**URL:** <https://community.icinga.com/t/question-where-are-service-state-and-service-state-id-stored/3424>\
**Category:** Icinga 2\
**Tags:** icinga2\
**Created:** [February 6, 2020, 3:52pm UTC](https://community.icinga.com/t/question-where-are-service-state-and-service-state-id-stored/3424 "2020-02-06T15:52:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PedroMSantosD](https://community.icinga.com/user_avatar/community.icinga.com/pedromsantosd/32/2435_2.png) [@PedroMSantosD](https://community.icinga.com/u/PedroMSantosD)\
**Post date:** [February 6, 2020, 3:52pm UTC](https://community.icinga.com/t/question-where-are-service-state-and-service-state-id-stored/3424/1 "2020-02-06T15:52:41Z")

</div>

Hi,  
I have defined a service that needs to send the last service.state and service.state\_id to the checkcommand

```auto
object CheckCommand "some-command" {
    command = ["python", CustomPluginDir + "monitor_this.py"]
    arguments += {
.....
        "--service_name" = {
        value = "$service_name$"
      }
      "--last_state" = {
        value = "$service.state$"
      }
      "--last_state_id" = {
        value = "$service.state_id$"
      }
    }

```

I have noticed, that when the service is changed to a different zone, the check is executed with the default values:

```auto
(from the api: https://localhost:5665/v1/objects/services )
                "last_check_result": {
                    "active": true,
                    "check_source": "icinga",
                    "command": [
                        "python",
                        "/.../monitor_this.py",
                        ...
                        "--last_state",
                        "UNKNOWN",
                        "--last_state_id",
                        "3",
...

```

Can you tell me where are the values for this runtime objects are stored ?

are they local to the icinga-satellite node?  
are they shared among the two icinga-satellites in the zone?  
are they pooled from the “master” zone ?

Thanks in advance,

---

<div class="post-metadata">

**Author:** ![dnsmichi](https://community.icinga.com/user_avatar/community.icinga.com/dnsmichi/32/7721_2.png) [@dnsmichi](https://community.icinga.com/u/dnsmichi)\
**Post date:** [February 6, 2020, 6:43pm UTC](https://community.icinga.com/t/question-where-are-service-state-and-service-state-id-stored/3424/2 "2020-02-06T18:43:18Z")

</div>

Hi,

the runtime macros are evaluated upon check execution. Wherever the service check is fired, this evaluates to their runtime state. Can you share a concrete example how you move the service, and which zone tree is used here?

Cheers,  
Michael

---

<div class="post-metadata">

**Author:** ![rsx](https://community.icinga.com/user_avatar/community.icinga.com/rsx/32/2094_2.png) [@rsx](https://community.icinga.com/u/rsx)\
**Post date:** [February 7, 2020, 7:55am UTC](https://community.icinga.com/t/question-where-are-service-state-and-service-state-id-stored/3424/3 "2020-02-07T07:55:01Z")

</div>

You could use something like this:

> vars.icinga\_current\_state = {{get\_service(host.name, “your service name”).state}}

Within your check command definition you could than access this variable e.g.:

```auto
      "-x" = {
         value = "$icinga_current_state$"
         description = "Current state in Icinga"
         }

```

---

<div class="post-metadata">

**Author:** ![PedroMSantosD](https://community.icinga.com/user_avatar/community.icinga.com/pedromsantosd/32/2435_2.png) [@PedroMSantosD](https://community.icinga.com/u/PedroMSantosD)\
**Post date:** [February 7, 2020, 8:48am UTC](https://community.icinga.com/t/question-where-are-service-state-and-service-state-id-stored/3424/4 "2020-02-07T08:48:42Z")

</div>

Hi,

we have a hughe datacenter, named ABC, so we are in need of having 6 satellites in there. we do an automated split in 3 children zones: ABC-a , ABC-b, ABC-c, and we have this particular service, that requires the service state.

We have found that when our split script happens to move the host with said service from one zone to the other, the check execution passes the “Unknown” state “3”, ; instead of the value that same service had on the other zone,  
which is in line with the idea of the satellite-node generating the check doing the service evaluation.

Thanks for the reply, I’ll look for a work-around

---

<div class="post-metadata">

**Author:** ![dnsmichi](https://community.icinga.com/user_avatar/community.icinga.com/dnsmichi/32/7721_2.png) [@dnsmichi](https://community.icinga.com/u/dnsmichi)\
**Post date:** [February 7, 2020, 9:10am UTC](https://community.icinga.com/t/question-where-are-service-state-and-service-state-id-stored/3424/5 "2020-02-07T09:10:02Z")

</div>

> [@PedroMSantosD](#):
>
> We have found that when our split script

Can you share that script, and its design? It would add to understand the described problem here.

Cheers,  
Michael

---

<div class="post-metadata">

**Author:** ![PedroMSantosD](https://community.icinga.com/user_avatar/community.icinga.com/pedromsantosd/32/2435_2.png) [@PedroMSantosD](https://community.icinga.com/u/PedroMSantosD)\
**Post date:** [February 7, 2020, 9:13am UTC](https://community.icinga.com/t/question-where-are-service-state-and-service-state-id-stored/3424/6 "2020-02-07T09:13:34Z")

</div>

will check with my boss, not sure if I can.
