ncareau / Mikro-Watch

Get Mikrotik's accounting data and push it to influxdb.
MIT License
28 stars 8 forks source link

Run docker on RaspberryPi #21

Open stal1n274 opened 2 years ago

stal1n274 commented 2 years ago

Can it be launched on RaspberryPi?

I see this error:

standard_init_linux.go:228: exec user process caused: exec format error
standard_init_linux.go:228: exec user process caused: exec format error
standard_init_linux.go:228: exec user process caused: exec format error
standard_init_linux.go:228: exec user process caused: exec format error
standard_init_linux.go:228: exec user process caused: exec format error
ncareau commented 2 years ago

Hmm. it should as I publish arm docker image too. What is the image (or the command) you are running ? Can you also let me know what raspberry pi and os you are using ? I will try to replicate the issue.

stal1n274 commented 2 years ago

Thanks for answering.

My Docker stack that I use in Portainer:

version: '3'
services:
    mikro-watch:
        image: ncareau/mikro-watch
        container_name: mikro-watch
        environment:
            - MIKROTIK_IP=192.168.88.1
            - NETWORK_RANGE=192.168.88.1-192.168.88.255
            - INFLUXDB_HOST=192.168.88.17
            - INFLUXDB_USER=<user>
            - INFLUXDB_PASS=<pass>
            - INFLUXDB_DATABASE=influxdb
            - DNS_REVERSE_LOOKUP=false
            - DNS_REVERSE_LOOKUP_TRIM_SUFFIX=false
        restart : unless-stopped 

I am using Raspberry Pi 4 Model B Rev 1.4 with 8GB My OS is openmediavault 5.6.16-1

image

ncareau commented 2 years ago

I have pushed the correct images on dockerhub. Previously I only pushed multiarch iamges on github, but now i'm pushing them on both github and dockerhub. Your config as-is should now work. Can you test it and report the result please ? Thank you.

stal1n274 commented 2 years ago

Thank you for your efforts. Unfortunately, I have the same issue: image

And I cannot connect into this container's console to verify connection to InfluxDB or check other logs.

stal1n274 commented 2 years ago

However, I deployed this container using the following command:

docker run -d --name mikro-watch \
    -e MIKROTIK_IP=192.168.88.1 \
    -e NETWORK_RANGE=192.168.88.1-192.168.88.255 \
    -e INFLUXDB_HOST=192.168.88.17 \
    -e INFLUXDB_USER=<user> \
    -e INFLUXDB_PASS=<pass> \
    -e INFLUXDB_DATABASE=influxdb \
    -e DNS_REVERSE_LOOKUP=false \
    -e DNS_REVERSE_LOOKUP_TRIM_SUFFIX=false \
    ncareau/mikro-watch

And there is another error:

cURL error 28: Connection time-out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)

cURL error 28: Connection time-out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)

cURL error 28: Connection time-out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)

cURL error 28: Connection time-out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)

I tried to change the address of INFLUXDB_HOST to other IPs that is assigned in docker but without any luck: 172.20.0.1 172.20.0.2 and even http://monitoring_influxdb:8086 like Grafana is using

Here is my containers in Portainer for monitoring, including Influxdb: image

ncareau commented 2 years ago

For the first error, (exec format error). It feels like portainer or your config isn't getting the latest docker image. Is there a button to force pull or are you able to redo your config from scratch so that it pulls the latest image ?

As for the curl error, it feels like it's because your mikrotik is not allowing the accounting data to be access by a web server ? Make sure you can access it manually using your browser : http://routerIP/accounting/ip.cgi

More info here : https://wiki.mikrotik.com/wiki/Manual:IP/Accounting

stal1n274 commented 2 years ago

Thank you for your answer!

Accounting was really disabled on my router. I've enabled it and checked via web browser, it works now. image

I redeployed the docker image using the latest docker image as you wrote and it was installed correctly. No more errors like 'exec format error'.

But I still see only these:

cURL error 28: Connection time-out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
cURL error 28: Connection time-out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
cURL error 28: Connection time-out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)
cURL error 28: Connection time-out (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)

How can I debug this from shell in docker image? There is no even ping command :)

stal1n274 commented 2 years ago

I figured out how to use curlin the image. Looks like the issue is related to network configuration:

root@3e639f73b085:/# curl http://192.168.88.1/accounting/ip.cgi
curl: (28) Connection time-out
ncareau commented 2 years ago

In the mikrotik configuration for webaccess to the accounting data, there is a range of allowed ip that you have to set. Make sure that you have opened is enough that both your pi and the computer you are testing have access.

Are you testing the access on the same machine that you are testing the curl ?

stal1n274 commented 2 years ago

In the mikrotik configuration for webaccess to the accounting data, there is a range of allowed ip that you have to set. Make sure that you have opened is enough that both your pi and the computer you are testing have access.

Yeah, I put there 192.168.88.0/24 and after that had access from my computer but not from Pi. I even changed this to 0.0.0.0/0 and had the same result.

Both RaspberryPi and PC are in the same network 192.168.88.0/24

Are you testing the access on the same machine that you are testing the curl ?

Yes. Is there some possibility to install the command ping into this container?

I even tried to use different kinds of networks during creating the stack: https://docs.docker.com/network/ I see that other my working containers are using network_mode: host and they have access to all hosts in local network. So, my current config for Mikro-Watch is the following:

version: '3'
services:
    mikro-watch:
        image: ncareau/mikro-watch
        container_name: mikro-watch
        network_mode: host
        environment:
            - MIKROTIK_IP=192.168.88.1
            - NETWORK_RANGE=192.168.88.1-192.168.88.255
            - INFLUXDB_HOST=192.168.88.17
            - INFLUXDB_USER=<user>
            - INFLUXDB_PASS=<pass>
            - INFLUXDB_DATABASE=influxdb
            - DNS_REVERSE_LOOKUP=false
            - DNS_REVERSE_LOOKUP_TRIM_SUFFIX=false
        restart : unless-stopped 

But it has the same issue cURL error 28: Connection time-out How I can use command telnet inside this container? And maybe you have any ideas that I can try?

ncareau commented 2 years ago

I totally forgot that the script now default to using https. You have to add MIKROTIK_PROTO=http in your environment variables to target http endpoint. Can you try it with that ? I will update the doc so that it's clearer.

stal1n274 commented 2 years ago

I tried:

latest: Pulling from ncareau/mikro-watch
4e5300249f84: Pull complete
2dd9f480a07d: Pull complete
541b04bc4262: Pull complete
4f0c01531f1a: Pull complete
795d99c90538: Pull complete
38cb1b4f5e78: Pull complete
8b6fc1762bfa: Pull complete
6ee12697b466: Pull complete
41061d958844: Pull complete
ca3cb26e708d: Pull complete
3991ad2b63e2: Pull complete
aa83c1dd4e8d: Pull complete
be6377b47417: Pull complete
d63261be74d0: Pull complete
Digest: sha256:d7876357e3f6dbb0626babc8b5b88eba049be98eabf237f1497d1a1d5430943c
Status: Downloaded newer image for ncareau/mikro-watch:latest
a82209afc993aa929afa84dcdb316d82ca5a7bf19a06efb2fc961187eefd5d18

But the result is the same:

curl: (28) Connection time-out

ncareau commented 2 years ago

Can you share your config for your latest test, i believe it should look like this :

version: '3'
  services:
      mikro-watch:
          image: ncareau/mikro-watch
          container_name: mikro-watch
          network_mode: host
          environment:
              - MIKROTIK_IP=192.168.88.1
              - MIRKOTIK_PROTO=http
              - NETWORK_RANGE=192.168.88.1-192.168.88.255
              - INFLUXDB_HOST=192.168.88.17
              - INFLUXDB_USER=<user>
              - INFLUXDB_PASS=<pass>
              - INFLUXDB_DATABASE=influxdb
              - DNS_REVERSE_LOOKUP=false
              - DNS_REVERSE_LOOKUP_TRIM_SUFFIX=false
          restart : unless-stopped 
stal1n274 commented 2 years ago

Here is my config for the stack:

version: '3'
services:
    mikro-watch:
        image: ncareau/mikro-watch
        container_name: mikro-watch
        network_mode: host
        environment:
            - MIKROTIK_PROTO=http
            - MIKROTIK_IP=192.168.88.1
            - NETWORK_RANGE=192.168.88.1-192.168.88.255
            - INFLUXDB_HOST=192.168.88.17
            - INFLUXDB_USER=<user>
            - INFLUXDB_PASS=<pass>
            - INFLUXDB_DATABASE=influxdb
            - DNS_REVERSE_LOOKUP=false
            - DNS_REVERSE_LOOKUP_TRIM_SUFFIX=false
        restart : unless-stopped 

Also, I've tried to create docker container with the same result using this command in my RaspberryPi terminal:

docker run -d --name mikro-watch --network host \
    -e MIKROTIK_PROTO=http \
    -e MIKROTIK_IP=192.168.88.1 \
    -e NETWORK_RANGE=192.168.88.1-192.168.88.255 \
    -e INFLUXDB_HOST=192.168.88.17 \
    -e INFLUXDB_USER=<user> \
    -e INFLUXDB_PASS=<pass> \
    -e INFLUXDB_DATABASE=influxdb \
    -e DNS_REVERSE_LOOKUP=false \
    -e DNS_REVERSE_LOOKUP_TRIM_SUFFIX=false \
    ncareau/mikro-watch
stal1n274 commented 2 years ago

I realized today, that this container doesn't have access to any network at all.

ncareau commented 2 years ago

Hehe, well that would certainly explain this behavior. Is this something you can/want to change ?

stal1n274 commented 2 years ago

Is this something you can/want to change ?

Yes, please. Could you please test it on RaspberryPi if it is working? I'm afraid that it is broken. Something is missing in it, that network is not available from it at all.

It would be good to add into this docker container such utility as net-tools for debugging. I tried to do this manually but had no success. My config (as you can see I had added only net-tools utility):

pi@raspberrypi:~/projects/Mikro-Watch $ cat Dockerfile
FROM php:7.4-cli

RUN apt-get update && apt-get clean && \
            apt-get --allow-insecure-repositories install -y zip net-tools

RUN docker-php-ext-install pcntl bcmath

RUN curl -sS https://getcomposer.org/installer | \
            php -- --install-dir=/usr/bin/ --filename=composer

COPY . /app

WORKDIR /app

RUN php /usr/bin/composer install --no-dev --no-interaction

CMD [ "php", "./mikro-watch",  "daemon" ]

Tried to build:

$ docker build .
Sending build context to Docker daemon  554.5kB
Step 1/8 : FROM php:7.4-cli
 ---> e196894ee135
Step 2/8 : RUN apt-get update && apt-get clean &&           apt-get --allow-insecure-repositories install -y zip net-tools
 ---> Running in 86b72b257a6f
Get:1 http://security.debian.org/debian-security bullseye-security InRelease [44.1 kB]
Get:2 http://deb.debian.org/debian bullseye InRelease [116 kB]
Get:3 http://deb.debian.org/debian bullseye-updates InRelease [39.3 kB]
Err:1 http://security.debian.org/debian-security bullseye-security InRelease
  At least one invalid signature was encountered.
Err:2 http://deb.debian.org/debian bullseye InRelease
  At least one invalid signature was encountered.
Err:3 http://deb.debian.org/debian bullseye-updates InRelease
  At least one invalid signature was encountered.
Reading package lists...
W: GPG error: http://security.debian.org/debian-security bullseye-security InRelease: At least one invalid signature was encountered.
E: The repository 'http://security.debian.org/debian-security bullseye-security InRelease' is not signed.
W: GPG error: http://deb.debian.org/debian bullseye InRelease: At least one invalid signature was encountered.
E: The repository 'http://deb.debian.org/debian bullseye InRelease' is not signed.
W: GPG error: http://deb.debian.org/debian bullseye-updates InRelease: At least one invalid signature was encountered.
E: The repository 'http://deb.debian.org/debian bullseye-updates InRelease' is not signed.
The command '/bin/sh -c apt-get update && apt-get clean &&          apt-get --allow-insecure-repositories install -y zip net-tools' returned a non-zero code: 100
$

Seems that there is no chance to build this container directly on my Raspberry