librenms / docker

LibreNMS Docker image
MIT License
691 stars 278 forks source link

Enable billing module #419

Closed charlyforot closed 8 months ago

charlyforot commented 10 months ago

Description

What

I noticed that there is no way to enable billing without modifying the cron file inside the container.

Currently, to enable billing we have to :

*/5 * * * * /opt/librenms/poll-billing.php >> /dev/null 2>&1
01  * * * * /opt/librenms/billing-calculate.php >> /dev/null 2>&1

We could not add them to the librenms crontab because of this error :

librenms-dispatcher1:~$ crontab -e
crontab: must be suid to work properly

How

Maybe, we could add an environment variable called LIBRENMS_BILLING (default : false). If set to True, we automatically add the config line (enable_billing) in config.d/ and the two lines in the cron file.

Why

To avoid enabling billing by manually changing root crontab inside the container.

MarcHagen commented 10 months ago

You can volume mount 09-custom-init.sh at /etc/cont-init.d/09-custom-init.sh. Contents:

#!/usr/bin/with-contenv bash

# Enable billing module
lnms config:set enable_billing true

This will enable the billing in LibreNMS

The sidecar poller is already doing billing polls for you. Even if you not doing the sidecar thing, it should still be enabled and work. image

LoveSkylark commented 9 months ago

In Kubernetes I have a container that runs a job once after server has started and configures this along with other tweaks:

apiVersion: batch/v1
kind: Job
metadata:
  name: depl-librenms
  namespace: {{ .Release.Name }}
  annotations:
    "helm.sh/hook": post-install,post-upgrade
    "helm.sh/hook-delete-policy": hook-succeeded
  labels:
{{ include "common.labels" . | indent 4 }}
spec:
spec:
  template:
    spec:
      containers:
      - name: depl-librenms
        image: {{ .Values.application.image | quote }}
        args:
          - /bin/sh 
          - "-c"
          - |
            su librenms 
            lnms config:set device_display_default    '{{ "{{" }} $sysName_fallback }}'
            lnms config:set snmp.community            '{{ .Values.application.SNMPcommunity | toJson }}'
            lnms config:set webui.graph_type          {{ .Values.application.lnms.graphs.type | quote }}
            lnms config:set webui.dynamic_graphs      {{ .Values.application.lnms.graphs.dynamic | quote }}
            lnms config:set enable_syslog             {{ .Values.application.syslogng.enable | quote }}
            lnms config:set syslog_purge              {{ .Values.application.syslogng.purge | quote }}
            lnms config:set show_services             {{ .Values.application.lnms.services.enable | quote }}
            lnms config:set service_services_enabled  {{ .Values.application.lnms.services.enable | quote }}
            # Billing;
            lnms config:set enable_billing            {{ .Values.application.lnms.billing.enable | quote }}
            # Parsing;
            lnms config:set customers_descr.2         {{ .Values.application.lnms.parsing.customers | quote }}
            lnms config:set transit_descr.2           {{ .Values.application.lnms.parsing.transit | quote }}
            lnms config:set peering_descr.2           {{ .Values.application.lnms.parsing.peering | quote }}
            lnms config:set core_descr.2              {{ .Values.application.lnms.parsing.core | quote }}

This is Kubernetes but Docker Compose can do very similar things, I think it would look something like this:

version: '3'

services:

  librenms:
    image: librenms/librenms:latest
    #normal docker config her

  job:
    image: librenms/librenms:latest
    restart: "no" 
    # needs to be able to connect to DB
    depends_on: 
      - librenms 
    command: 
      - bash -c "lnms config:set enable_billing true && exit 0"

I've suggested in adding a SIDECAR for CLI configuration like this before, but It was deemed unnecessary since default server will work just fine.

charlyforot commented 8 months ago

Thank you all for your help !

The billing module looked enabled on my LibreNMS UI but the billing did not work.

However, the config.php file contained the following line :

$config['enable_billing'] = 1;

Instead of :

$config['enable_billing'] = true;

No error logs to catch this one.

I corrected the value from 1 to true and it's now working !