> For the complete documentation index, see [llms.txt](https://portal-integracao.intelbras.com.br/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://portal-integracao.intelbras.com.br/ct-3000-2pb-4pb/obtendo-eventos-em-tempo-real/eventmanager.md).

# EventManager

O EventManager requer que o servidor solicite aos dispositivos o envio dos eventos em um formato de "pooling". Este end-point encaminha eventos de alarmes e alguns eventos relacionados a leituras.

Para o funcionamento correto é necessário que a requisição seja feita em polling e modo Stream, caso contrário o dispositivo não irá retornar os eventos.

Por este motivo esta chamada não irá funcionar no Postman.

### Obtendo eventos via eventManager

#### Requisição - GET

<mark style="color:green;">`GET`</mark>`http://192.168.1.201/cgi-bin/eventManager.cgi?action=attach&codes=[All]&heartbeat=5`

| param       | type   | description                                                                                                                                                      |
| ----------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `codes` \*  | String | Código de evento a ser filtrado, pode ser utilizado: "All", "DoorNotClosed", "BreakIn", "Duress", "AlarmLocal", "ChassisIntruded", "ButtonExit", "AccessControl" |
| `heartbeat` | String | Valor pode ser de 1 a 5. Define o intervalo de envio da mensagem ao cliente com a informação hearbeat                                                            |

#### Retorno - *multipart-mixed*:

```sh

--myboundary
Content-Type: text/plain
Content-Length:315

Code=AccessControl;action=Pulse;index=0;data={
   "CardName" : "",
   "CardNo" : "12EA3004",
   "CardType" : 0,
   "CreateTime" : 1629721071,
   "Door" : 0,
   "ErrorCode" : 0,
   "Method" : 1,
   "ReaderID" : "1",
   "Status" : 1,
   "Type" : "Entry",
   "UTC" : 1629721071,
   "UserID" : "1",
   "UserType" : 0
}

--myboundary
Content-Type: text/plain
Content-Length:85
Code=BreakIn;action=Pulse;index=0;data={
"Name" : "SS-1",
"UTC" : 1598250815
}

--myboundary
Content-Type: text/plain
Content-Length:91
Code=DoorNotClosed;action=Start;index=0;data={
"Name" : "SS-1",
"UTC" : 1598250817
}

Code=_Button_;action=Pulse;index=0;data={
"Local" : true,
"ReaderID" : "1",
"Type" : "Button"
}

Code=Duress;action=Pulse;index=0;data={
   "Name" : "Door",
   "UTC" : 1629721071,
   "UserID" : "1"
}
```

**Tipos de Codes:** "DoorNotClosed", "BreakIn", "Duress", "AlarmLocal", "ChassisIntruded", "ButtonExit", "AccessControl"

#### Tipos de eventos retornados

| Code                       | Descrição do evento                                                                                  |
| -------------------------- | ---------------------------------------------------------------------------------------------------- |
| Upgrade                    | Evento ocorre quando o dispositivo inicia uma atualização de firmware                                |
| Reboot                     | Evento de reinício do dispositivo                                                                    |
| BreakIn                    | Evento de arrombamento de porta                                                                      |
| DoorStatus                 | Evento de status da porta                                                                            |
| AlarmLocal                 | Evento de disparo de alarme local                                                                    |
| NewFile                    | Evento de cadastro de arquivo no dispositivo                                                         |
| UpdateFile                 | Evento de Atualização de arquivo do dispositivo                                                      |
| DoorNotClosed              | Evento de porta não fechada                                                                          |
| NetworkChange              | Evento de alteração de configurações da rede                                                         |
| AccessControl              | Evento de controle de acesso                                                                         |
| KeepLightOn / KeepLightOff | Evento referente a luz noturna que se ativa dependendo da iluminação do local                        |
| ScreenSaver                | Evento Referente ao estado da proteção de tela do dispositivo caso esteja configurada.               |
| TimeChange                 | Evento de alteração de hora do dispositivo normalmente acompanha o BeforeModifyTime e o ModifiedTime |
| ManagerLog                 | Evento de logs referente a alteração feitas via interface web                                        |
| Button / ButtonExit        | Evento referente ao botão de Saida                                                                   |
| Duress                     | Evento ocorre quando é realizado a passagem de uma credencial de coação                              |
| ChassisIntruded            | Evento ocorre quando é realizado a tentativa de intrusão do dispositivo (Remoção da parede/Tamper)   |

{% hint style="warning" %}
**Observações:** Para realizar o recebimento dos eventos de alarme é necessário que seja ativado os alarmes nas configurações do dispositivos.
{% endhint %}

#### Exemplos

{% tabs %}
{% tab title="Python" %}

```python
import requests

url = "http://192.168.3.87/cgi-bin/eventManager.cgi?action=attach&codes=[All]"
digest_auth = requests.auth.HTTPDigestAuth('admin', 'acesso1234')

response = requests.get(url, auth=digest_auth, stream=True, timeout=60, verify=False)

empty_lines = 0
event = {}

for chunk in response.iter_lines():
        print(chunk)

        if chunk == ''.encode():
            empty_lines += 1
            if empty_lines == 2:
                empty_lines = 0
                print(event)
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const request = require('request');

const url = "http://192.168.3.87/cgi-bin/eventManager.cgi?action=attach&codes=[All]"
const auth = {
  user: 'admin',
  pass: 'acesso1234',
  sendImmediately: false
}

request.get(url, {
  auth: auth,
  timeout: 60 * 1000,
  strictSSL: false,
})
.on('data', function(chunk) {
  console.log(chunk.toString());

  if (chunk.toString() === '') {
      empty_lines++;
      if (empty_lines === 2) {
          empty_lines = 0;
          console.log(event);
      }
  }
})
.on('error', function(err) {
  console.error(err);
});
```

{% endtab %}

{% tab title="Curl" %}

```shellscript
curl --digest -u "admin:admin12345" -g "http://192.168.1.201/cgi-bin/eventManager.cgi?action=attach&codes=[All]" > test_EventManager.txt
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://portal-integracao.intelbras.com.br/ct-3000-2pb-4pb/obtendo-eventos-em-tempo-real/eventmanager.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
