diff --git a/integrations/promunifi/.gitignore b/integrations/promunifi/.gitignore index 9ad81108..61d1785f 100644 --- a/integrations/promunifi/.gitignore +++ b/integrations/promunifi/.gitignore @@ -1,14 +1,14 @@ /up.conf /unifi-poller -/*.gz -/*.1 -/*.deb -/*.rpm -/*.pkg +/unifi-poller*.gz +/unifi-poller*.1 +/unifi-poller*.deb +/unifi-poller*.rpm +/unifi-poller*.pkg +/unifi-poller.macos +/unifi-poller.linux /vendor .DS_Store *~ -/package_build +/package_build_* /release -/unifi-poller.macos -/unifi-poller.linux diff --git a/integrations/promunifi/Makefile b/integrations/promunifi/Makefile index 7898ba48..25f3ad59 100644 --- a/integrations/promunifi/Makefile +++ b/integrations/promunifi/Makefile @@ -1,58 +1,164 @@ -PACKAGE=./cmd/unifi-poller -BINARY=unifi-poller -VERSION=`git tag -l --merged | tail -n1` +BINARY:=unifi-poller +URL=https://github.com/davidnewhall/unifi-poller +MAINT="david at sleepers dot pro" +DESC="This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database." +PACKAGE:=./cmd/$(BINARY) +VERSION:=$(shell git tag -l --merged | tail -n1 | tr -d v) +ITERATION:=$(shell git rev-list --count HEAD) -all: man unifi-poller +all: man build # Prepare a release. Called in Travis CI. -release: clean test man linux macos rpm deb osxpkg +release: clean test $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb $(BINARY)-$(VERSION).pkg + # Prepareing a release! mkdir -p release - gzip -9k unifi-poller.linux - gzip -9k unifi-poller.macos - mv unifi-poller.macos.gz unifi-poller.linux.gz release/ - cp *.rpm *.deb *.pkg release/ + gzip -9 $(BINARY).linux + gzip -9 $(BINARY).macos + mv $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb \ + $(BINARY)-$(VERSION).pkg $(BINARY).macos.gz $(BINARY).linux.gz release/ +# Delete all build assets. clean: - rm -f `echo $(PACKAGE)|cut -d/ -f3`{.macos,.linux,.1,}{,.gz} - rm -f `echo $(PACKAGE)|cut -d/ -f3`{_,-}*.{deb,rpm,pkg} - rm -rf package_build release + # Cleaning up. + rm -f $(BINARY){.macos,.linux,.1,}{,.gz} + rm -f $(BINARY){_,-}*.{deb,rpm,pkg} + rm -rf package_build_* release -build: unifi-poller -unifi-poller: - go build -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE) +# Build a man page from a markdown file using ronn. +man: $(BINARY).1.gz +$(BINARY).1.gz: + # Building man page. + @ronn --version > /dev/null || (echo "Ronn missing. Install ronn: $(URL)/wiki/Ronn" && false) + ronn < "$(PACKAGE)/README.md" | gzip -9 > "$(BINARY).1.gz" -linux: unifi-poller.linux -unifi-poller.linux: - GOOS=linux go build -o unifi-poller.linux -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE) +# Binaries -macos: unifi-poller.macos -unifi-poller.macos: - GOOS=darwin go build -o unifi-poller.macos -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE) +build: $(BINARY) +$(BINARY): + go build -o $(BINARY) -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE) +linux: $(BINARY).linux +$(BINARY).linux: + # Building linux binary. + GOOS=linux go build -o $(BINARY).linux -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE) + +macos: $(BINARY).macos +$(BINARY).macos: + # Building darwin binary. + GOOS=darwin go build -o $(BINARY).macos -ldflags "-w -s -X main.Version=$(VERSION)" $(PACKAGE) + +# Packages + +rpm: clean $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm +$(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm: check_fpm package_build_linux + @echo "Building 'rpm' package for $(BINARY) version '$(VERSION)-$(ITERATION)'." + fpm -s dir -t rpm \ + --name $(BINARY) \ + --rpm-os linux \ + --version $(VERSION) \ + --iteration $(ITERATION) \ + --after-install scripts/after-install.sh \ + --before-remove scripts/before-remove.sh \ + --license MIT \ + --url $(URL) \ + --maintainer $(MAINT) \ + --description $(DESC) \ + --chdir package_build_linux + +deb: clean $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb +$(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb: check_fpm package_build_linux + @echo "Building 'deb' package for $(BINARY) version '$(VERSION)-$(ITERATION)'." + fpm -s dir -t deb \ + --name $(BINARY) \ + --version $(VERSION) \ + --iteration $(ITERATION) \ + --after-install scripts/after-install.sh \ + --before-remove scripts/before-remove.sh \ + --license MIT \ + --url $(URL) \ + --maintainer $(MAINT) \ + --description $(DESC) \ + --chdir package_build_linux + +osxpkg: clean $(BINARY)-$(VERSION).pkg +$(BINARY)-$(VERSION).pkg: check_fpm package_build_osx + @echo "Building 'osx' package for $(BINARY) version '$(VERSION)-$(ITERATION)'." + fpm -s dir -t osxpkg \ + --name $(BINARY) \ + --version $(VERSION) \ + --iteration $(ITERATION) \ + --after-install scripts/after-install.sh \ + --osxpkg-identifier-prefix com.github.davidnewhall \ + --license MIT \ + --url $(URL) \ + --maintainer $(MAINT) \ + --description $(DESC) \ + --chdir package_build_osx + +# OSX packages use /usr/local because Apple doesn't allow writing many other places. +package_build_osx: man macos + # Building package environment for macOS. + mkdir -p $@/usr/local/bin $@/usr/local/etc/$(BINARY) $@/Library/LaunchAgents + mkdir -p $@/usr/local/share/man/man1 $@/usr/local/share/doc/$(BINARY) $@/usr/local/var/log/unifi-poller + # Copying the binary, config file and man page into the env. + cp $(BINARY).macos $@/usr/local/bin/$(BINARY) + cp *.1.gz $@/usr/local/share/man/man1 + cp examples/*.conf.example $@/usr/local/etc/$(BINARY)/ + cp examples/* $@/usr/local/share/doc/$(BINARY)/ + cp init/launchd/com.github.davidnewhall.$(BINARY).plist $@/Library/LaunchAgents/ + +# Build an environment that can be packaged for linux. +package_build_linux: man linux + # Building package environment for linux. + mkdir -p $@/usr/bin $@/etc/$(BINARY) $@/lib/systemd/system + mkdir -p $@/usr/share/man/man1 $@/usr/share/doc/$(BINARY) + # Copying the binary, config file, unit file, and man page into the env. + cp $(BINARY).linux $@/usr/bin/$(BINARY) + cp *.1.gz $@/usr/share/man/man1 + cp examples/*.conf.example $@/etc/$(BINARY)/ + cp examples/up.conf.example $@/etc/$(BINARY)/up.conf + cp examples/* $@/usr/share/doc/$(BINARY)/ + cp init/systemd/$(BINARY).service $@/lib/systemd/system/ + +check_fpm: + @fpm --version > /dev/null || (echo "FPM missing. Install FPM: https://fpm.readthedocs.io/en/latest/installing.html" && false) + +# Extras + +# Run code tests and lint. test: lint + # Testing. go test -race -covermode=atomic $(PACKAGE) - lint: + # Checking lint. golangci-lint run --enable-all -D gochecknoglobals -man: unifi-poller.1.gz -unifi-poller.1.gz: - scripts/build_manpages.sh ./ - -rpm: man linux - scripts/build_linux_packages.sh rpm - -deb: man linux - scripts/build_linux_packages.sh deb - -osxpkg: man macos - scripts/build_osx_package.sh - -install: man - scripts/local_install.sh +# Deprecated. +install: + @echo - Local installation with the Makefile is no longer possible. + @echo If you wish to install the application manually, check out the wiki: \ + https://github.com/davidnewhall/unifi-poller/wiki/Installation + @echo - Otherwise, build and install a package: make rpm, make deb, make osxpkg + @echo See the Package Install wiki for more info: \ + https://github.com/davidnewhall/unifi-poller/wiki/Package-Install +# If you installed with `make install` run `make uninstall` before installing a binary package. +# This will remove the package install from macOS, it will not remove a package install from Linux. uninstall: - scripts/local_uninstall.sh + @echo " ==> You must run make uninstall as root on Linux. Recommend not running as root on macOS." + [ -x /bin/systemctl ] && /bin/systemctl disable $(BINARY) || true + [ -x /bin/systemctl ] && /bin/systemctl stop $(BINARY) || true + [ -x /bin/launchctl ] && [ -f ~/Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist ] \ + && /bin/launchctl unload ~/Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist || true + [ -x /bin/launchctl ] && [ -f /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist ] \ + && /bin/launchctl unload /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist || true + rm -rf /usr/local/{etc,bin,share/doc}/$(BINARY) + rm -f ~/Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist + rm -f /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist || true + rm -f /etc/systemd/system/$(BINARY).service /usr/local/share/man/man1/$(BINARY).1.gz + [ -x /bin/systemctl ] && /bin/systemctl --system daemon-reload || true + @[ -f /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist ] && echo " ==> Unload and delete this file manually:" && echo " sudo launchctl unload /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist" && echo " sudo rm -f /Library/LaunchAgents/com.github.davidnewhall.$(BINARY).plist" || true +# Don't run this unless you're ready to debug untested vendored dependencies. deps: dep ensure -update diff --git a/integrations/promunifi/README.md b/integrations/promunifi/README.md index df5a2333..cc89530e 100644 --- a/integrations/promunifi/README.md +++ b/integrations/promunifi/README.md @@ -37,12 +37,6 @@ for making this dashboard; it gave me a fantastic start to making my own. # What now... -- Better Linux support and testing - -I only, personally, run this on a Mac 10.13.something. I know others are using -Linux and it's working, but I need more feedback. Does the unit file work? Are -you able to stop and start the service? Does the Makefile do the right things? - - Are there other devices that need to be included? I have: switch, router, access point. Three total, and the type structs are @@ -55,7 +49,10 @@ Issue and lets discuss. - Better Installation instructions. If you're a nerd you can probably figure it out. I'd still like some pretty -pictures and maybe even a Twitch VOD. +pictures and maybe even a Twitch VOD. Update: The installation has been +simplified tremendously with the +[creation of binary packages](https://github.com/davidnewhall/unifi-poller/wiki/Package-Install). +More to come! - Radios, Frequencies, Interfaces, vAPs @@ -63,11 +60,6 @@ My access points only seem to have two radios, one interface and vAP per radio. I'm not sure if the graphs, as-is, provide enough insight into APs with other configurations. Help me figure that out? -- It possibly loses access to the controller at some point. - -I noticed metrics stop updating after a while. I think the new code will help -isolate why this happens. We may need to issue a reconnect and get a new cookie. - # What's it look like? Here's a picture of the Client dashboard. diff --git a/integrations/promunifi/cmd/unifi-poller/README.md b/integrations/promunifi/cmd/unifi-poller/README.md index 691b7de3..64bce18e 100644 --- a/integrations/promunifi/cmd/unifi-poller/README.md +++ b/integrations/promunifi/cmd/unifi-poller/README.md @@ -1,9 +1,9 @@ -unifi-poller(1) -- Utility to poll Unifi Metrics and drop them into InfluxDB +unifi-poller(1) -- Utility to poll UniFi Controller Metrics and store them in InfluxDB === ## SYNOPSIS -`unifi-poller -c /usr/local/etc/unifi-poller.conf` +`unifi-poller -c /etc/unifi-poller.conf` ## DESCRIPTION @@ -26,14 +26,16 @@ unifi-poller(1) -- Utility to poll Unifi Metrics and drop them into InfluxDB ## CONFIGURATION -* Config File Default Location: /usr/local/etc/unifi-poller/up.conf +* Config File Default Location: /etc/unifi-poller/up.conf `Config File Parameters` `sites` default: ["default"] This list of strings should represent the names of sites on the unifi controller that will be polled for data. Pass `all` in the list to - poll all sites. + poll all sites. On startup, the application prints out all site names + found in the controller; they're cryptic, but they have the human-name + next to them. The cryptic names go into the config file `sites` list. `interval` default: 30s How often to poll the controller for updated client and device data. @@ -94,10 +96,10 @@ Example Use: `1m`, `5h`, `100ms`, `17s`, `1s45ms`, `1m3s` * Garrett Bjerkhoel (original code) ~ 2016 * David Newhall II (rewritten) ~ 4/20/2018 +* David Newhall II (still going) ~ 6/7/2019 ## LOCATION * https://github.com/davidnewhall/unifi-poller -* /usr/local/bin/unifi-poller -* config-file: /usr/local/etc/unifi-poller/up.conf +* UniFi Library: https://github.com/golift/unifi * previously: https://github.com/dewski/unifi diff --git a/integrations/promunifi/cmd/unifi-poller/config.go b/integrations/promunifi/cmd/unifi-poller/config.go index 44b84be1..1b75860a 100644 --- a/integrations/promunifi/cmd/unifi-poller/config.go +++ b/integrations/promunifi/cmd/unifi-poller/config.go @@ -7,7 +7,7 @@ var Version = "development" const ( // App defaults in case they're missing from the config. - defaultConfFile = "/usr/local/etc/unifi-poller/up.conf" + defaultConfFile = "/etc/unifi-poller/up.conf" defaultInterval = 30 * time.Second defaultInfxDb = "unifi" defaultInfxUser = "unifi" diff --git a/integrations/promunifi/cmd/unifi-poller/main.go b/integrations/promunifi/cmd/unifi-poller/main.go index ca26976d..066d5e48 100644 --- a/integrations/promunifi/cmd/unifi-poller/main.go +++ b/integrations/promunifi/cmd/unifi-poller/main.go @@ -139,7 +139,7 @@ func GetConfig(configFile string) (Config, error) { // PollUnifiController runs forever, polling and pushing. func (c *Config) PollUnifiController(controller *unifi.Unifi, infdb influx.Client) { - log.Println("[INFO] Everyting checks out! Beginning Poller Routine.") + log.Println("[INFO] Everything checks out! Beginning Poller Routine.") ticker := time.NewTicker(c.Interval.value) for range ticker.C { diff --git a/integrations/promunifi/examples/README.md b/integrations/promunifi/examples/README.md index 90fa3dd3..d9799785 100644 --- a/integrations/promunifi/examples/README.md +++ b/integrations/promunifi/examples/README.md @@ -1,6 +1,6 @@ # Grafana Dashboards & Examples -This folder contains 3 grafana dashboards to get you started with the new data pool. +This folder contains 4 grafana dashboards to get you started with the new data pool. Import these into Grafana to quickly visualize data from your devices. Created with Grafana 6.2. diff --git a/integrations/promunifi/examples/unifi-usw-grafana-dash.json b/integrations/promunifi/examples/unifi-usw-grafana-dash.json index f221b4ab..a40c3ce2 100644 --- a/integrations/promunifi/examples/unifi-usw-grafana-dash.json +++ b/integrations/promunifi/examples/unifi-usw-grafana-dash.json @@ -53,7 +53,7 @@ "gnetId": null, "graphTooltip": 1, "id": null, - "iteration": 1559898667753, + "iteration": 1559898956053, "links": [ { "icon": "external link", @@ -3410,5 +3410,5 @@ "timezone": "", "title": "UniFi USW Insights", "uid": "HIKZ98GZz", - "version": 85 + "version": 87 } \ No newline at end of file diff --git a/integrations/promunifi/examples/up.conf.example b/integrations/promunifi/examples/up.conf.example index c1c13b18..16a814fe 100644 --- a/integrations/promunifi/examples/up.conf.example +++ b/integrations/promunifi/examples/up.conf.example @@ -1,7 +1,6 @@ -# unifi-poller primary configuration file. # -# copy this file to: /usr/local/etc/unifi-poller/up.conf # -# commented lines are defaults, uncomment to change. # -########################################################## +# unifi-poller primary configuration file. # +# commented lines are defaults, uncomment to change. # +###################################################### # If the controller has more than one site, specify which sites to poll here. # If only one site, "default" is likely the correct name. diff --git a/integrations/promunifi/init/launchd/com.github.davidnewhall.unifi-poller.plist b/integrations/promunifi/init/launchd/com.github.davidnewhall.unifi-poller.plist index d8a18294..cffcd1d9 100644 --- a/integrations/promunifi/init/launchd/com.github.davidnewhall.unifi-poller.plist +++ b/integrations/promunifi/init/launchd/com.github.davidnewhall.unifi-poller.plist @@ -15,8 +15,12 @@ KeepAlive StandardErrorPath - /usr/local/var/log/unifi-poller.log + /usr/local/var/log/unifi-poller/log StandardOutPath - /usr/local/var/log/unifi-poller.log + /usr/local/var/log/unifi-poller/log + UserName + nobody + GroupName + nobody diff --git a/integrations/promunifi/init/systemd/unifi-poller.service b/integrations/promunifi/init/systemd/unifi-poller.service index ba7d1bd7..ab5220ad 100644 --- a/integrations/promunifi/init/systemd/unifi-poller.service +++ b/integrations/promunifi/init/systemd/unifi-poller.service @@ -4,7 +4,7 @@ After=network.target Requires=network.target [Service] -ExecStart=/usr/local/bin/unifi-poller --config=/usr/local/etc/unifi-poller/up.conf +ExecStart=/usr/bin/unifi-poller --config=/etc/unifi-poller/up.conf Restart=always StandardOutput=syslog StandardError=syslog diff --git a/integrations/promunifi/scripts/after-install-osx.sh b/integrations/promunifi/scripts/after-install-osx.sh deleted file mode 100755 index bc2ad33c..00000000 --- a/integrations/promunifi/scripts/after-install-osx.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# This file is used by osxpkg packages. FPM use. - -# Copy the config file into place if it does not exist. -if [ ! -f /usr/local/etc/unifi-poller/up.conf ] && [ -f /usr/local/etc/unifi-poller/up.conf.example ]; then - cp /usr/local/etc/unifi-poller/up.conf.example /usr/local/etc/unifi-poller/up.conf -fi - -# Allow admins to change the configuration and write logs. -chgrp -R admin /usr/local/etc/unifi-poller -chmod -R g+wr /usr/local/etc/unifi-poller - -# Make sure admins can write logs. -chgrp admin /usr/local/var/log -chmod g=rwx /usr/local/var/log - -# This starts it as root. no no no .... not sure how to fix that. -# launchctl load /Library/LaunchAgents/com.github.davidnewhall.unifi-poller.plist diff --git a/integrations/promunifi/scripts/after-install.sh b/integrations/promunifi/scripts/after-install.sh index 2fb3cd87..820eccc2 100755 --- a/integrations/promunifi/scripts/after-install.sh +++ b/integrations/promunifi/scripts/after-install.sh @@ -1,7 +1,30 @@ #!/bin/bash -# This file is used by rpm and deb packages. FPM use. +# This file is used by deb, rpm and osx packages. +# FPM adds this as the after-install script. -systemctl daemon-reload -systemctl enable unifi-poller -systemctl restart unifi-poller +if [ "$(uname -s)" = "Darwin" ]; then + # Copy the config file into place if it does not exist. + if [ ! -f /usr/local/etc/unifi-poller/up.conf ] && [ -f /usr/local/etc/unifi-poller/up.conf.example ]; then + cp /usr/local/etc/unifi-poller/up.conf.example /usr/local/etc/unifi-poller/up.conf + fi + + # Allow admins to change the configuration and delete the docs. + chgrp -R admin /usr/local/etc/unifi-poller /usr/local/share/doc/unifi-poller + chmod -R g+wr /usr/local/etc/unifi-poller /usr/local/share/doc/unifi-poller + + # Make sure admins can delete logs. + chown -R nobody:admin /usr/local/var/log/unifi-poller + chmod 0775 /usr/local/var/log/unifi-poller + chmod -R g+rw /usr/local/var/log/unifi-poller + + # Restart the service - this starts the application as user nobody. + launchctl unload /Library/LaunchAgents/com.github.davidnewhall.unifi-poller.plist + launchctl load /Library/LaunchAgents/com.github.davidnewhall.unifi-poller.plist + +elif [ -x "/bin/systemctl" ]; then + # Reload and restart - this starts the application as user nobody. + /bin/systemctl daemon-reload + /bin/systemctl enable unifi-poller + /bin/systemctl restart unifi-poller +fi diff --git a/integrations/promunifi/scripts/before-remove.sh b/integrations/promunifi/scripts/before-remove.sh index 36ab63fe..83ae4004 100755 --- a/integrations/promunifi/scripts/before-remove.sh +++ b/integrations/promunifi/scripts/before-remove.sh @@ -6,5 +6,7 @@ if [ "$1" = "upgrade" ] || [ "$1" = "1" ] ; then exit 0 fi -systemctl stop unifi-poller -systemctl disable unifi-poller +if [ -x "/bin/systemctl" ]; then + /bin/systemctl stop unifi-poller + /bin/systemctl disable unifi-poller +fi diff --git a/integrations/promunifi/scripts/build_linux_packages.sh b/integrations/promunifi/scripts/build_linux_packages.sh deleted file mode 100755 index 9a6c5512..00000000 --- a/integrations/promunifi/scripts/build_linux_packages.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash - -# This script builds a deb or rpm package. Run by the Makefile. -# Use: `make rpm` or `make deb` - -OUTPUT=$1 -BINARY=unifi-poller -VERSION=$(git tag -l --merged | tail -n1 | tr -d v) - -if [ "$OUTPUT" != "deb" ] && [ "$OUTPUT" != "rpm" ]; then - echo "first argument must be 'deb' or 'rpm'" - exit 1 -fi - -fpm -h > /dev/null 2>&1 -if [ "$?" != "0" ]; then - echo "fpm missing. Install fpm: https://fpm.readthedocs.io/en/latest/installing.html" - exit 1 -fi - -echo "Building '${OUTPUT}' package for ${BINARY} version ${VERSION}." - -# eh, don't change these. -PREFIX= -BINFIX=/usr - -# Make a build environment. -rm -rf package_build -mkdir -p package_build${BINFIX}/bin package_build${PREFIX}/etc/${BINARY} package_build${BINFIX}/share/man/man1 - -# Copy the binary, config file and man page into the env. -cp ${BINARY}.linux package_build${BINFIX}/bin/${BINARY} -cp *.1.gz package_build${BINFIX}/share/man/man1 -cp examples/up.conf.example package_build${PREFIX}/etc/${BINARY}/up.conf - -# Fix the paths in the systemd unit file before copying it into the emv. -mkdir -p package_build/lib/systemd/system -sed "s#ExecStart.*#ExecStart=${BINFIX}/bin/${BINARY} --config=${PREFIX}/etc/${BINARY}/up.conf#" \ - init/systemd/unifi-poller.service > package_build/lib/systemd/system/${BINARY}.service - -# Make a package. -fpm -s dir -t ${OUTPUT} \ - --name ${BINARY} \ - --version ${VERSION} \ - --iteration $(git rev-list --all --count) \ - --after-install scripts/after-install.sh \ - --before-remove scripts/before-remove.sh \ - --license MIT \ - --url 'https://github.com/davidnewhall/unifi-poller' \ - --maintainer 'david at sleepers dot pro' \ - --description 'This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database.' \ - --chdir package_build diff --git a/integrations/promunifi/scripts/build_manpages.sh b/integrations/promunifi/scripts/build_manpages.sh deleted file mode 100755 index cf223e1b..00000000 --- a/integrations/promunifi/scripts/build_manpages.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# This file uses ronn to build a man page for unifi-poller. -set -o pipefail - -OUTPUT=$1 - -# This requires the installation of `ronn`: sudo gem install ronn -for f in cmd/*/README.md;do - # Strtip off cmd/ then strip off README to get the man-file name. - PKGNOCMD="${f#cmd/}" - PKG="${PKGNOCMD%/README.md}" - echo "Creating Man Page: ${f} -> ${OUTPUT}${PKG}.1.gz" - ronn < "$f" | gzip -9 > "${OUTPUT}${PKG}.1.gz" || \ - echo "If this produces an error. Install ronn; something like: sudo gem install ronn" -done diff --git a/integrations/promunifi/scripts/build_osx_package.sh b/integrations/promunifi/scripts/build_osx_package.sh deleted file mode 100755 index 08d1a57b..00000000 --- a/integrations/promunifi/scripts/build_osx_package.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -# This script builds a simple macos Installer pkg. Run by the Makefile. -# Use: `make osxpkg` - -OUTPUT=osxpkg -BINARY=unifi-poller -VERSION=$(git tag -l --merged | tail -n1 | tr -d v) - -fpm -h > /dev/null 2>&1 -if [ "$?" != "0" ]; then - echo "fpm missing. Install fpm: https://fpm.readthedocs.io/en/latest/installing.html" - exit 1 -fi - -echo "Building '${OUTPUT}' package for ${BINARY} version ${VERSION}." - -PREFIX=/usr/local -BINFIX=/usr/local - -# Make a build environment. -rm -rf package_build -mkdir -p package_build${BINFIX}/bin package_build${PREFIX}/etc/${BINARY} package_build${BINFIX}/share/man/man1 -mkdir -p package_build${PREFIX}/var/log - -# Copy the binary, config file and man page into the env. -cp ${BINARY}.macos package_build${BINFIX}/bin/${BINARY} -cp *.1.gz package_build${BINFIX}/share/man/man1 -cp examples/up.conf.example package_build${PREFIX}/etc/${BINARY}/ - -# Copy in launch agent. -mkdir -p package_build/Library/LaunchAgents -cp init/launchd/com.github.davidnewhall.unifi-poller.plist package_build/Library/LaunchAgents/ - -# Make a package. -fpm -s dir -t ${OUTPUT} \ - --name ${BINARY} \ - --version ${VERSION} \ - --iteration $(git rev-list --all --count) \ - --after-install scripts/after-install-osx.sh \ - --osxpkg-identifier-prefix com.github.davidnewhall \ - --license MIT \ - --maintainer 'david at sleepers dot pro' \ - --url 'https://github.com/davidnewhall/unifi-poller' \ - --description 'This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database.' \ - --chdir package_build diff --git a/integrations/promunifi/scripts/local_install.sh b/integrations/promunifi/scripts/local_install.sh deleted file mode 100755 index 74a082b0..00000000 --- a/integrations/promunifi/scripts/local_install.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -# This script creates a local installation of unifi-poller. -# Recommend using Makefile to invoke: make install -# Supports Linux (systemd only) and macOS. - -BINARY=unifi-poller - -echo "Installing unifi-poller. If you get errors, you may need sudo." - -# Install binary. -GOBIN=/usr/local/bin go install -ldflags "-w -s" ./... - -# Making config folders and installing man page. -mkdir -p /usr/local/etc/${BINARY} /usr/local/share/man/man1 -mv *.1.gz /usr/local/share/man/man1 - -# Installing config file, man page and launch agent or systemd unit file. -if [ ! -f /usr/local/etc/${BINARY}/up.conf ]; then - cp examples/up.conf.example /usr/local/etc/${BINARY}/up.conf -fi -if [ -d ~/Library/LaunchAgents ]; then - cp init/launchd/com.github.davidnewhall.${BINARY}.plist ~/Library/LaunchAgents -fi -if [ -d /etc/systemd/system ]; then - cp init/systemd/${BINARY}.service /etc/systemd/system -fi - -# Making systemd happy by telling it to reload. -if [ -x /bin/systemctl ]; then - /bin/systemctl --system daemon-reload - /bin/systemctl start unifi-poller - /bin/systemctl enable unifi-poller -fi - -echo "Installation Complete. Edit the config file @ /usr/local/etc/${BINARY}/up.conf" -echo "Then start the daemon with:" -if [ -d ~/Library/LaunchAgents ]; then - echo " launchctl load ~/Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist" -fi -if [ -x /bin/systemctl ]; then - echo " sudo /bin/systemctl restart ${BINARY}" -fi -echo "Examine the log file at: /usr/local/var/log/${BINARY}.log (logs may go elsewhere on linux, check syslog)" diff --git a/integrations/promunifi/scripts/local_uninstall.sh b/integrations/promunifi/scripts/local_uninstall.sh deleted file mode 100755 index fd5abce8..00000000 --- a/integrations/promunifi/scripts/local_uninstall.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash - -# This script removes a local installation of unifi-poller. -# Recommend using Makefile to invoke: make uninstall -# Supports Linux (systemd only) and macOS. - -BINARY=unifi-poller - -echo "Uninstall unifi-poller. You may need sudo on Linux. Do not use sudo on macOS." - -# Stopping the daemon -if [ -x /bin/systemctl ]; then - /bin/systemctl disable ${BINARY} - /bin/systemctl stop ${BINARY} -fi - -if [ -x /bin/launchctl ] && [ -f ~/Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist ]; then - echo Unloading ~/Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist - /bin/launchctl unload ~/Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist || true -fi - -if [ -x /bin/launchctl ] && [ -f /Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist ]; then - echo Unloading /Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist - /bin/launchctl unload /Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist || true - echo "Delete this file manually: sudo rm -f /Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist" -fi - -# Deleting config file, binary, man page, launch agent or unit file. -rm -rf /usr/local/{etc,bin}/${BINARY} /usr/local/share/man/man1/${BINARY}.1.gz -rm -f ~/Library/LaunchAgents/com.github.davidnewhall.${BINARY}.plist -rm -f /etc/systemd/system/${BINARY}.service - -# Making systemd happy by telling it to reload. -if [ -x /bin/systemctl ]; then - /bin/systemctl --system daemon-reload -fi