Bug 246105 - net-mgmt/librenms: add support for polling as a service
Summary: net-mgmt/librenms: add support for polling as a service
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Dan Langille
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-01 20:20 UTC by Dries Michiels
Modified: 2020-05-03 19:34 UTC (History)
0 users

See Also:
bugzilla: maintainer-feedback? (dvl)


Attachments
librenms.diff (6.37 KB, patch)
2020-05-01 20:20 UTC, Dries Michiels
no flags Details | Diff
librenms.diff (6.30 KB, patch)
2020-05-02 08:47 UTC, Dries Michiels
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dries Michiels freebsd_committer freebsd_triage 2020-05-01 20:20:23 UTC
Created attachment 214007 [details]
librenms.diff

This is a raw but working WIP for the port. I have not yet run time tested this on my setup. Also use ${WWWOWN} and ${WWWGRP} where applicable (these are defined variables in the ports framework) instead of using an in between variable.
Comment 1 Dan Langille freebsd_committer freebsd_triage 2020-05-01 20:27:53 UTC
I don't have time to read the PR/diff today.

Does this twitter thread sound like you're doing what I'm saying?

https://twitter.com/DLangille/status/1253324274447773707
Comment 2 Dries Michiels freebsd_committer freebsd_triage 2020-05-01 20:32:41 UTC
Ah yes, that's exactly what I was trying to add!
I didn't see your Tweet before you linked it just now, woops.
Hopefully you havent started working on it yet.
Comment 3 Dan Langille freebsd_committer freebsd_triage 2020-05-01 21:08:21 UTC
(In reply to Dries Michiels from comment #2)
I have not worked on this at all.

My goal was to get rid of Python 2.7
Comment 4 Dan Langille freebsd_committer freebsd_triage 2020-05-02 01:46:20 UTC
I think we should enable logging:

[dan@besser:~] $ echo /usr/local/bin/python3.7 /usr/local/www/librenms/librenms-service.py -m | sudo su -fm www
MainThread(ERROR):Could not import .env - check that the poller user can read the file, and that composer install has been run recently
Traceback (most recent call last):
  File "/usr/local/www/librenms/LibreNMS/service.py", line 166, in _get_config_data
    raise ImportError(".env does not contain a valid NODE_ID setting.")
ImportError: .env does not contain a valid NODE_ID setting.
[dan@besser:~] $
Comment 5 Dan Langille freebsd_committer freebsd_triage 2020-05-02 02:02:19 UTC
The dispatcher is running.  I'll leave it overnight.
Comment 6 Dan Langille freebsd_committer freebsd_triage 2020-05-02 02:23:16 UTC
Node id is created via:

$ php ~/tmp/uniqueid.php
5eacd76c3281a[dan@empty:~/librenms] $ 


where:

$ cat ~/tmp/uniqueid.php 
<?php

echo uniqid();
Comment 7 Dries Michiels freebsd_committer freebsd_triage 2020-05-02 08:47:27 UTC
Created attachment 214022 [details]
librenms.diff

Thanks for taking such a quick look at this! 

This patch rebases on top of 1.63, and enables syslog logging with -S (now /var/log/daemon.log captures the output of this service).

Given the Tweet of LibreNMS regard python2.7 I guess this is a viable way forward to just remove python2.7 support. https://twitter.com/LibreNMS/status/1256209304727715840

ATM I implemented them side by side to ease the user experience. Although if you OK, I can just remove the PYPOLLER option and incorporate the PYSERVICE dependencies right in the port as hard deps (no option as this will be the only and default method of polling with python2.7 removed).

The unique node ID is that only to be generated once when the service is started? Maybe we can add that as a function in the RC script. Or add an extra note in pkg-message.

Thanks for your direction in this!
Comment 8 Dan Langille freebsd_committer freebsd_triage 2020-05-02 12:54:18 UTC
(In reply to Dries Michiels from comment #7)
> This patch rebases on top of 1.63, and enables syslog logging with -S (now
> /var/log/daemon.log captures the output of this service).

That file isn't on my system.

/etc/syslog.conf does not have an entry for that file.

Does your system have this configured?
Comment 9 Dries Michiels freebsd_committer freebsd_triage 2020-05-02 13:06:05 UTC
Ah yes, its only default in FreeBSD 13 I see.
https://svnweb.freebsd.org/base?view=revision&revision=352460
Comment 10 Dan Langille freebsd_committer freebsd_triage 2020-05-02 19:46:38 UTC
I created https://reviews.freebsd.org/D24671 with my latest changes
Comment 11 Dan Langille freebsd_committer freebsd_triage 2020-05-02 20:05:06 UTC
(In reply to Dan Langille from comment #10)
I think the new instructions in files/pkg-message.in need to be rearranged into a logical order.
Comment 12 Dan Langille freebsd_committer freebsd_triage 2020-05-03 12:55:34 UTC
I'm using this:

command_args="-S -o /var/log/$name/$name.log -p $pidfile $procname /usr/local/www/librenms/librenms-service.py -m"


which requires this first:

sudo touch /var/log/librenms/librenms.log
sudo chown www /var/log/librenms/librenms.log
Comment 13 Dries Michiels freebsd_committer freebsd_triage 2020-05-03 13:34:12 UTC
Yeah thats fine, although I would opt to go for only the file log mechanism then (only -o, not combined with -S). Given that the port already logs other librenms stuff to that same logfile. We should probably make it configurable in the rc script too. Otherwise it will be logging double.
Comment 14 Dan Langille freebsd_committer freebsd_triage 2020-05-03 14:48:08 UTC
That makes me think we should log the service to librenms-service.log instead
Comment 15 Dan Langille freebsd_committer freebsd_triage 2020-05-03 16:27:21 UTC
I have:

* updated the rc.d script to remove -S and log to a new filename
* adding an entry to UPDATING
* pre-created the log file because daemon creates it with UID root
* amended pkg-message and it now includes an install and a update message

Details at https://reviews.freebsd.org/D24671
Comment 16 commit-hook freebsd_committer freebsd_triage 2020-05-03 19:32:11 UTC
A commit references this bug:

Author: dvl
Date: Sun May  3 19:31:29 UTC 2020
New revision: 533804
URL: https://svnweb.freebsd.org/changeset/ports/533804

Log:
  Add support for polling as a service

  Two new options

  * PYPOLLER  - default, deprecated, needs Python 2.7
  * PYSERVICE - Dispatcher service, recompile required

  HEADS UP HEADS UP

  Polling via cron job is now deprecated. Please use the Dispatcher.

  LibreNMS will be dropping support for PHP 7.1 and Python 2 in the next release
  expected May 31 2020.  see https://community.librenms.org/t/dropping-support-for-php-7-1-and-python-2/11851

  Your existing crontab entries for the PYPOLLER option will be going away.

  You can migrate to the PYSERVICE option of LibreNMS now.

  PR:		246105
  Submitted by:	Dries Michiels <driesm.michiels@gmail.com>

Changes:
  head/UPDATING
  head/net-mgmt/librenms/Makefile
  head/net-mgmt/librenms/files/librenms.in
  head/net-mgmt/librenms/files/pkg-message.in
Comment 17 Dan Langille freebsd_committer freebsd_triage 2020-05-03 19:34:30 UTC
Committed.  Thank you.