├── .dockerignore ├── .github └── workflows │ ├── ci-jobs.yml │ ├── codeql-analysis.yml │ └── release-jobs.yml ├── .gitignore ├── LICENSE ├── README.md ├── VersionMaster.txt ├── build.sh ├── build ├── CreateManPage.sh ├── CreateRpmPackage.sh ├── GithubEnv.sh ├── InstallProgram.sh ├── LaunchpadPublish │ ├── Dockerfile.bookworm │ ├── Dockerfile.bullseye │ ├── Dockerfile.buster │ ├── Dockerfile.focal │ ├── Dockerfile.jammy │ ├── Dockerfile.kinetic │ ├── Dockerfile.lunar │ ├── Dockerfile.mantic │ ├── Dockerfile.noble │ ├── Dockerfile.oracular │ ├── Dockerfile.plucky │ └── PublishLaunchpad.sh ├── PatchPagesContent.sh ├── PrepareRelease.sh ├── PublishLaunchpadInDocker.sh ├── PublishRpmInDocker.sh ├── additional-pages │ ├── Dockerfile │ └── UpdatePagesRepo.sh ├── go.mod ├── go.sum ├── pages │ ├── mkdocs.yml │ └── requirements.txt ├── rpm-build │ ├── BuildInDocker.sh │ └── Dockerfile ├── rpm-publish │ ├── Dockerfile.fedora28 │ ├── Dockerfile.fedora35 │ ├── Dockerfile.fedora36 │ ├── Dockerfile.fedora37 │ ├── Dockerfile.fedora38 │ ├── Dockerfile.fedora39 │ ├── Dockerfile.fedora40 │ ├── Dockerfile.fedora41 │ ├── Dockerfile.fedora42 │ └── RpmPublish.sh └── workflow │ ├── go.mod │ ├── go.sum │ ├── mage.go │ └── magefiles │ └── magefile.go ├── docs ├── DeveloperDocs │ ├── ActionsAndReleases.md │ ├── Compile.md │ └── Hints.md ├── Index.md ├── Installation │ ├── InstallationGuide.md │ └── SupportedVersions.md ├── UserDocs │ ├── Concept.md │ ├── ServiceIntegration.md │ └── UserGuide.md └── assets │ ├── Samba-Dashboard.png │ ├── import_dashboard_with_json.png │ ├── samba-exporter.icon.png │ └── samba-exporter.icon.svg ├── install ├── debian │ ├── changelog │ ├── compat │ ├── conffiles │ ├── control │ ├── copyright │ ├── postinst │ ├── postrm │ ├── prerm │ ├── rules │ └── samba-exporter.manpages ├── etc │ └── default │ │ ├── samba_exporter │ │ └── samba_statusd ├── fedora │ ├── samba-exporter.from_gradle.spec │ └── samba-exporter.from_source.spec ├── lib │ └── systemd │ │ └── system │ │ ├── samba_exporter.service │ │ └── samba_statusd.service └── usr │ └── bin │ └── start_samba_statusd ├── src ├── example │ └── grafana │ │ └── SambaService.json ├── man │ ├── samba_exporter.1.ronn │ ├── samba_statusd.1.ronn │ └── start_samba_statusd.1.ronn ├── page │ └── index.html └── tobi.backfrak.de │ ├── cmd │ ├── samba_exporter │ │ ├── go.mod │ │ ├── go.sum │ │ ├── main.go │ │ ├── main_test.go │ │ ├── parameters_test.go │ │ └── paramters.go │ └── samba_statusd │ │ ├── go.mod │ │ ├── go.mod.gopsutil-v2 │ │ ├── go.sum │ │ ├── go.sum.gopsutil-v2 │ │ ├── main.go │ │ ├── main_test.go │ │ ├── parameters_test.go │ │ └── paramters.go │ └── internal │ ├── commonbl │ ├── consolelogger.go │ ├── consolelogger_test.go │ ├── error.go │ ├── error_test.go │ ├── filelogger.go │ ├── filelogger_test.go │ ├── go.mod │ ├── loggerinterface.go │ ├── loggerinterface_test.go │ ├── parameters.go │ ├── pipes.go │ ├── pipes_test.go │ ├── protocol.go │ ├── protocol_test.go │ ├── queue.go │ ├── queue_test.go │ └── testResponse.go │ ├── smbexporterbl │ ├── pipecomunication │ │ ├── errors.go │ │ ├── errors_test.go │ │ ├── go.mod │ │ ├── handler.go │ │ └── handler_test.go │ ├── smbexporter │ │ ├── exporter.go │ │ ├── exporter_test.go │ │ ├── go.mod │ │ └── go.sum │ ├── smbstatusreader │ │ ├── go.mod │ │ ├── reader.go │ │ └── reader_test.go │ └── statisticsGenerator │ │ ├── generator_test.go │ │ ├── gernerator.go │ │ ├── go.mod │ │ ├── smbdprocess.go │ │ └── smbdprocess_test.go │ ├── smbstatusdbl │ ├── go.mod │ ├── go.mod.gopsutil-v2 │ ├── go.sum │ ├── go.sum.gopsutil-v2 │ ├── psdatagenerator.go │ └── psdatagenerator_test.go │ ├── smbstatusout │ ├── go.mod │ └── testdata.go │ └── testhelper │ ├── go.mod │ ├── testlogger.go │ └── testlogger_test.go └── test ├── import └── functions.sh ├── installationTest ├── RunInstallationTest.sh └── test.smb.conf └── integrationTest ├── docker ├── Dockerfile.bookworm └── Dockerfile.ubuntu └── scripts └── RunIntegrationTests.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | # Files and folders not to copy into the docker containers 2 | 3 | src/ 4 | pkg/ 5 | logs/ 6 | build.sh 7 | 8 | VersionMaster.txt -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: 17 | - '**' 18 | pull_request: 19 | # The branches below must be a subset of the branches above 20 | branches: [ "main" ] 21 | 22 | jobs: 23 | analyze: 24 | name: Analyze 25 | runs-on: ubuntu-24.04 26 | permissions: 27 | actions: read 28 | contents: read 29 | security-events: write 30 | 31 | strategy: 32 | fail-fast: false 33 | matrix: 34 | language: [ 'go' ] 35 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] 36 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 37 | 38 | steps: 39 | - name: Checkout repository 40 | uses: actions/checkout@v3 41 | 42 | # Initializes the CodeQL tools for scanning. 43 | - name: Initialize CodeQL 44 | uses: github/codeql-action/init@v2 45 | with: 46 | languages: ${{ matrix.language }} 47 | # If you wish to specify custom queries, you can do so here or in a config file. 48 | # By default, queries listed here will override any specified in a config file. 49 | # Prefix the list here with "+" to use these queries and those in the config file. 50 | 51 | # Details on CodeQL's query packs refer to : https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 52 | queries: security-extended,security-and-quality 53 | 54 | # ℹ️ Command-line programs to run using the OS shell. 55 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 56 | 57 | # If the Autobuild fails above, remove it and uncomment the following three lines. 58 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 59 | 60 | - run: | 61 | echo "Run, Build Application using script" 62 | ./build.sh build 63 | 64 | - name: Perform CodeQL Analysis 65 | uses: github/codeql-action/analyze@v2 66 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | **/.vscode/ 2 | **\.vscode\ 3 | 4 | debug 5 | debug.test 6 | bin/* 7 | bin\* 8 | pkg/* 9 | pkg\* 10 | logs/* 11 | logs\* 12 | src/github.com/* 13 | src\github.com\* 14 | tmp/* 15 | tmp\* 16 | 17 | *.zip 18 | *.log 19 | *.pipe 20 | 21 | out.abs 22 | out.abc 23 | 24 | test/integrationTest/scripts/assert.sh 25 | debian/samba-exporter** 26 | install/debian/samba-exporter** 27 | 28 | src/man/samba_exporter.1.html 29 | src/man/samba_exporter.1 30 | src/man/samba_exporter.1.gz 31 | src/man/start_samba_statusd.1.html 32 | src/man/start_samba_statusd.1 33 | src/man/start_samba_statusd.1.gz 34 | src/man/samba_statusd.1.html 35 | src/man/samba_statusd.1 36 | src/man/samba_statusd.1.gz 37 | 38 | debian/start_samba_statusd.1 39 | debian/.debhelper/generated/samba-exporter/installed-by-dh_installman 40 | debian/.debhelper/generated/samba-exporter/installed-by-dh_installdocs 41 | debian/samba_statusd.1 42 | debian/samba_exporter.1 43 | debian/debhelper-build-stamp 44 | 45 | build/rpm-publish/samba-exporter.from_source.spec 46 | 47 | build/pages/site/** 48 | build/pages/__pycache__ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Samba Exporter 2 | 3 | A [prometheus exporter](https://prometheus.io/docs/instrumenting/exporters/) for statistic data of the [samba file server](https://www.samba.org/). 4 | 5 | ![Screenshot of dashboard for the samba service](./docs/assets/Samba-Dashboard.png) 6 | 7 | It uses [smbstatus](https://www.samba.org/samba/docs/current/man-html/smbstatus.1.html) and the [proc fs](https://en.wikipedia.org/wiki/Procfs) to collect the data and converts the result into prometheus style data. 8 | The prometheus style data can be requested manually on port 9922 using a http client. Or a prometheus database sever can be configured to collect the data by scraping port 9922 on the samba server. 9 | 10 | ## Documentation 11 | 12 | For detailed documentation please take a look at the [projects page](https://imker25.github.io/samba_exporter/Index/) or read in the [docs](./docs/Index.md) folder. 13 | 14 | There are **RPM** and **DEB** packages for several Linux distributions for you ready to install. You may want to take a look at the [Supported Distributions and Versions](./docs/Installation/SupportedVersions.md) and the [Installation Guide](./docs/Installation/InstallationGuide.md) 15 | -------------------------------------------------------------------------------- /VersionMaster.txt: -------------------------------------------------------------------------------- 1 | 1.37 -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2021 by tobi@backfrak.de. All 4 | # rights reserved. Use of this source code is governed 5 | # by a BSD-style license that can be found in the 6 | # LICENSE file. 7 | 8 | 9 | # Script to run the mage build workflow for the project. 10 | # - running the script without paramates just recompiles the project 11 | # - running the script with -l list the targets 12 | # - running the script with -h shows the mage help 13 | 14 | 15 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 16 | 17 | pushd "$SCRIPT_DIR/build/workflow" 18 | go run ./mage.go -d "$SCRIPT_DIR/build/workflow/magefiles" -w "$SCRIPT_DIR" "$@" 19 | build_exit_code=$? 20 | if [ "$build_exit_code" != 0 ]; then 21 | echo "Error: 'go run' exit with code '$build_exit_code'" 22 | fi 23 | popd 24 | 25 | exit $build_exit_code -------------------------------------------------------------------------------- /build/CreateManPage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ###################################################################################### 3 | # Copyright 2021 by tobi@backfrak.de. All 4 | # rights reserved. Use of this source code is governed 5 | # by a BSD-style license that can be found in the 6 | # LICENSE file. 7 | # ###################################################################################### 8 | # Script to convert markdown style man pages into actual man pages using ronn 9 | # ###################################################################################### 10 | 11 | # ################################################################################################################ 12 | # variable asigenment 13 | # ################################################################################################################ 14 | RONN=/usr/bin/ronn 15 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 16 | BRANCH_ROOT="$SCRIPT_DIR/.." 17 | SRC_DIR="$BRANCH_ROOT/src/man" 18 | LOG_DIR="$BRANCH_ROOT/logs" 19 | PACKAGE_NAME=$(cat $LOG_DIR/PackageName.txt) 20 | DEFAULT_PACKAGE_ROOT="tmp" 21 | 22 | 23 | # ################################################################################################################ 24 | # function definition 25 | # ################################################################################################################ 26 | function print_usage() { 27 | echo "Usage: $0 [package-root]" 28 | echo "-help Print this help" 29 | echo "package-root (optional) The path to the package. (default $DEFAULT_PACKAGE_ROOT)" 30 | echo "" 31 | echo "This script will convert markdown style man pages into actual man pages using ronn" 32 | } 33 | 34 | # ################################################################################################################ 35 | # functional code 36 | # ################################################################################################################ 37 | 38 | if [ "$1" == "-help" ]; then 39 | print_usage 40 | exit 0 41 | fi 42 | 43 | if [ "$1" != "" ]; then 44 | PACKAGE_ROOT="$BRANCH_ROOT/$1/$PACKAGE_NAME" 45 | else 46 | PACKAGE_ROOT="$BRANCH_ROOT/$DEFAULT_PACKAGE_ROOT/$PACKAGE_NAME" 47 | fi 48 | 49 | if [ ! -f $RONN ];then 50 | echo "ERROR: ronn package is not installed" 51 | exit 1 52 | fi 53 | 54 | pushd "$BRANCH_ROOT" >> /dev/null 55 | 56 | # Clean old files 57 | if [ -f "$SRC_DIR/samba_exporter.1" ];then 58 | rm -f "$SRC_DIR/samba_exporter.1" 59 | fi 60 | if [ -f "$SRC_DIR/samba_exporter.1.html" ];then 61 | rm -f "$SRC_DIR/samba_exporter.1.html" 62 | fi 63 | if [ -f "$SRC_DIR/samba_exporter.1.gz" ];then 64 | rm -f "$SRC_DIR/samba_exporter.1.gz" 65 | fi 66 | if [ -f "$SRC_DIR/start_samba_statusd.1.html" ];then 67 | rm -f "$SRC_DIR/start_samba_statusd.1.html" 68 | fi 69 | if [ -f "$SRC_DIR/start_samba_statusd.1.gz" ];then 70 | rm -f "$SRC_DIR/start_samba_statusd.1.gz" 71 | fi 72 | if [ -f "$SRC_DIR/start_samba_statusd.1" ];then 73 | rm -f "$SRC_DIR/start_samba_statusd.1" 74 | fi 75 | if [ -f "$SRC_DIR/samba_statusd.1.html" ];then 76 | rm -f "$SRC_DIR/samba_statusd.1.html" 77 | fi 78 | if [ -f "$SRC_DIR/samba_statusd.1.gz" ];then 79 | rm -f "$SRC_DIR/samba_statusd.1.gz" 80 | fi 81 | if [ -f "$SRC_DIR/samba_statusd.1" ];then 82 | rm -f "$SRC_DIR/samba_statusd.1" 83 | fi 84 | 85 | 86 | # Generate new files 87 | $RONN "$SRC_DIR/samba_exporter.1.ronn" 88 | gzip --keep "$SRC_DIR/samba_exporter.1" 89 | $RONN "$SRC_DIR/samba_statusd.1.ronn" 90 | gzip --keep "$SRC_DIR/samba_statusd.1" 91 | $RONN "$SRC_DIR/start_samba_statusd.1.ronn" 92 | gzip --keep "$SRC_DIR/start_samba_statusd.1" 93 | 94 | # Install the man page into the package if dir exists 95 | if [ -d "$PACKAGE_ROOT" ]; then 96 | echo "Install to tmp package $PACKAGE_ROOT" 97 | mkdir -p "$PACKAGE_ROOT/usr/share/man/man1" 98 | cp "$SRC_DIR/samba_statusd.1.gz" "$PACKAGE_ROOT/usr/share/man/man1" 99 | cp "$SRC_DIR/start_samba_statusd.1.gz" "$PACKAGE_ROOT/usr/share/man/man1" 100 | cp "$SRC_DIR/samba_exporter.1.gz" "$PACKAGE_ROOT/usr/share/man/man1" 101 | fi 102 | 103 | popd 104 | -------------------------------------------------------------------------------- /build/CreateRpmPackage.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ###################################################################################### 3 | # Copyright 2022 by tobi@backfrak.de. All 4 | # rights reserved. Use of this source code is governed 5 | # by a BSD-style license that can be found in the 6 | # LICENSE file. 7 | # ###################################################################################### 8 | # Script to build and test the project using a fedora container with creating a binary rpm at the end 9 | 10 | # ################################################################################################################ 11 | # variable asigenment 12 | # ################################################################################################################ 13 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 14 | BRANCH_ROOT="$SCRIPT_DIR/.." 15 | 16 | # ################################################################################################################ 17 | # functional code 18 | # ################################################################################################################ 19 | echo "Create output folders" 20 | echo "# ###################################################################" 21 | mkdir -vp "$BRANCH_ROOT/bin" 22 | mkdir -vp "$BRANCH_ROOT/logs" 23 | mkdir -vp "$BRANCH_ROOT/tmp" 24 | 25 | echo "" 26 | echo "# ###################################################################" 27 | echo "Build the container to run the package build" 28 | echo "docker build --file \"$SCRIPT_DIR/rpm-build/Dockerfile\" --tag rpm-build \"$SCRIPT_DIR/rpm-build/\"" 29 | echo "Loggig to '$BRANCH_ROOT/logs/docker-build-fedora.log'" 30 | docker build --file "$SCRIPT_DIR/rpm-build/Dockerfile" --tag rpm-build --build-arg USER=${USER} --build-arg UID=$(id -u) --build-arg GID=$(id -g) "$SCRIPT_DIR/rpm-build/" > $BRANCH_ROOT/logs/docker-build-fedora.log 2>&1 31 | if [ "$?" != "0" ]; then 32 | echo "Error: Docker container build failed" 33 | exit 1 34 | fi 35 | # Move the docker build log to other folder, so it will not be deleted during the "./build.sh clean" when the container runs 36 | mv -v "$BRANCH_ROOT/logs/docker-build-fedora.log" "/tmp" 37 | echo "" 38 | echo "# ###################################################################" 39 | buildFailed="false" 40 | echo "Run the container to create the rpm package" 41 | docker run --env HOME=/home/${USER} \ 42 | --env USER=${USER} \ 43 | --mount type=bind,source="$BRANCH_ROOT",target="/build_area" \ 44 | --user $(id -u):$(id -g) \ 45 | -i rpm-build \ 46 | /bin/bash -c "/BuildInDocker.sh" 47 | 48 | if [ "$?" != "0" ]; then 49 | buildFailed="true" 50 | fi 51 | # Move the docker build log back to log folder 52 | mv -v "/tmp/docker-build-fedora.log" "$BRANCH_ROOT/logs" 53 | 54 | echo "Delete the container image used for this build" 55 | docker rmi -f $(docker images --filter=reference="rpm-build" -q) 56 | 57 | if [ "$buildFailed" == "true" ]; then 58 | echo "Error: RPM build in container failed" 59 | exit 1 60 | fi 61 | 62 | echo "" 63 | echo "# ###################################################################" 64 | echo "All done" 65 | echo "# ###################################################################" 66 | exit 0 -------------------------------------------------------------------------------- /build/GithubEnv.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ###################################################################################### 3 | # Copyright 2021 by tobi@backfrak.de. All 4 | # rights reserved. Use of this source code is governed 5 | # by a BSD-style license that can be found in the 6 | # LICENSE file. 7 | # ###################################################################################### 8 | # Script to read infos from files into the github environment during a actions workflow 9 | # ###################################################################################### 10 | 11 | # Read package info from install/debian/control file 12 | controlFile="./install/debian/control" 13 | while IFS= read -r line 14 | do 15 | if [[ $line = Description:* ]]; then 16 | desc=${line/Description: /} 17 | echo "SAMBA_EXPORTER_PACKAGE_DESCRIPTION=$desc" 18 | echo "SAMBA_EXPORTER_PACKAGE_DESCRIPTION=$desc" >> $GITHUB_ENV 19 | fi 20 | if [[ $line = Depends:* ]]; then 21 | dep=${line/Depends: /} 22 | echo "SAMBA_EXPORTER_PACKAGE_DEPENDS=$dep" 23 | echo "SAMBA_EXPORTER_PACKAGE_DEPENDS=$dep" >> $GITHUB_ENV 24 | fi 25 | if [[ $line = Maintainer:* ]]; then 26 | dev=${line/Maintainer: /} 27 | echo "SAMBA_EXPORTER_PACKAGE_MAINTAINER=$dev" 28 | echo "SAMBA_EXPORTER_PACKAGE_MAINTAINER=$dev" >> $GITHUB_ENV 29 | fi 30 | if [[ $line = Package:* ]]; then 31 | pack=${line/Package: /} 32 | echo "SAMBA_EXPORTER_PACKAGE=$pack" 33 | echo "SAMBA_EXPORTER_PACKAGE=$pack" >> $GITHUB_ENV 34 | fi 35 | done < "$controlFile" 36 | 37 | # Read version infos from build log files 38 | echo " GITHUB_REF= $GITHUB_REF" 39 | packageName=$(cat logs/PackageName.txt) 40 | echo "SAMBA_EXPORTER_PACKAGE_NAME=$packageName" 41 | echo "SAMBA_EXPORTER_PACKAGE_NAME=$packageName" >> $GITHUB_ENV 42 | packageVersion=$(cat logs/Version.txt) 43 | echo "SAMBA_EXPORTER_VERSION=$packageVersion" 44 | echo "SAMBA_EXPORTER_VERSION=$packageVersion" >> $GITHUB_ENV 45 | rpmVersion=$(cat ./logs/ShortVersion.txt) 46 | echo "SAMBA_EXPORTER_RPM_VERSION=$rpmVersion" 47 | echo "SAMBA_EXPORTER_RPM_VERSION=$rpmVersion" >> $GITHUB_ENV -------------------------------------------------------------------------------- /build/LaunchpadPublish/Dockerfile.bookworm: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishLaunchpadInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./PublishLaunchpad.sh when this container get started 9 | # ###################################################################################### 10 | 11 | # Use the packages target version (bookworm = debian 12) as base image 12 | FROM debian:bookworm 13 | 14 | # Setup the system and install needed packages 15 | ENV DEBIAN_FRONTEND="noninteractive" 16 | ENV TZ="Europe/London" 17 | RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget \ 18 | curl \ 19 | libc6 \ 20 | golang-1.19 \ 21 | gzip \ 22 | ronn\ 23 | debhelper \ 24 | golang-any \ 25 | golang-github-go-kit-kit-dev \ 26 | golang-github-prometheus-client-golang-dev \ 27 | golang-github-prometheus-common-dev \ 28 | golang-gopkg-alecthomas-kingpin.v2-dev \ 29 | golang-github-shirou-gopsutil-dev \ 30 | dh-golang \ 31 | debhelper \ 32 | dh-make \ 33 | lintian \ 34 | git-buildpackage \ 35 | git \ 36 | openssh-client \ 37 | procps \ 38 | gpg 39 | 40 | # Copy the script 41 | COPY PublishLaunchpad.sh /PublishLaunchpad.sh 42 | RUN chmod 777 /PublishLaunchpad.sh 43 | 44 | ARG USER 45 | ARG UID 46 | ARG GID 47 | 48 | # Configure git 49 | RUN mkdir -p /home/${USER} &&\ 50 | chmod 770 /home/${USER} && \ 51 | chown ${UID}:${GID} /home/${USER} 52 | 53 | RUN addgroup --gid ${GID} ${USER} &&\ 54 | adduser --system --quiet --home /home/${USER} --gid ${GID} --uid ${UID} --gecos "builder" ${USER} || true -------------------------------------------------------------------------------- /build/LaunchpadPublish/Dockerfile.bullseye: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishLaunchpadInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./PublishLaunchpad.sh when this container get started 9 | # ###################################################################################### 10 | 11 | # Use the packages target version (focal = ubuntu 20.04) as base image 12 | FROM debian:bullseye 13 | 14 | # Setup the system and install needed packages 15 | ENV DEBIAN_FRONTEND="noninteractive" 16 | ENV TZ="Europe/London" 17 | RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget \ 18 | curl \ 19 | libc6 \ 20 | golang-1.15 \ 21 | gzip \ 22 | ronn\ 23 | debhelper \ 24 | golang-any \ 25 | golang-github-go-kit-kit-dev \ 26 | golang-github-prometheus-client-golang-dev \ 27 | golang-github-prometheus-common-dev \ 28 | golang-gopkg-alecthomas-kingpin.v2-dev \ 29 | golang-github-shirou-gopsutil-dev \ 30 | dh-golang \ 31 | debhelper \ 32 | dh-make \ 33 | lintian \ 34 | git-buildpackage \ 35 | git \ 36 | openssh-client \ 37 | procps \ 38 | gpg 39 | 40 | # Copy the script 41 | COPY PublishLaunchpad.sh /PublishLaunchpad.sh 42 | RUN chmod 777 /PublishLaunchpad.sh 43 | 44 | ARG USER 45 | ARG UID 46 | ARG GID 47 | 48 | # Configure git 49 | RUN mkdir -p /home/${USER} &&\ 50 | chmod 770 /home/${USER} && \ 51 | chown ${UID}:${GID} /home/${USER} 52 | 53 | RUN addgroup --gid ${GID} ${USER} &&\ 54 | adduser --system --quiet --home /home/${USER} --gid ${GID} --uid ${UID} --gecos "builder" ${USER} || true -------------------------------------------------------------------------------- /build/LaunchpadPublish/Dockerfile.buster: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishLaunchpadInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./PublishLaunchpad.sh when this container get started 9 | # ###################################################################################### 10 | 11 | # Use the packages target version (focal = ubuntu 20.04) as base image 12 | FROM debian:buster 13 | 14 | # Setup the system and install needed packages 15 | ENV DEBIAN_FRONTEND="noninteractive" 16 | ENV TZ="Europe/London" 17 | RUN echo 'deb http://deb.debian.org/debian buster-backports main' > /etc/apt/sources.list.d/backports.list 18 | RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget \ 19 | curl \ 20 | libc6 \ 21 | golang-1.15 \ 22 | golang-1.15-go \ 23 | golang-1.15-doc \ 24 | gzip \ 25 | ronn\ 26 | debhelper \ 27 | golang-github-go-kit-kit-dev \ 28 | golang-github-prometheus-client-golang-dev/buster-backports \ 29 | golang-github-prometheus-common-dev/buster-backports \ 30 | golang-github-mwitkow-go-conntrack-dev/buster-backports \ 31 | golang-github-prometheus-client-model-dev/buster-backports \ 32 | golang-gopkg-alecthomas-kingpin.v2-dev\ 33 | golang-github-shirou-gopsutil-dev \ 34 | dh-golang/buster-backports \ 35 | debhelper/buster-backports \ 36 | dwz/buster-backports \ 37 | dh-make \ 38 | lintian \ 39 | git-buildpackage \ 40 | git \ 41 | openssh-client \ 42 | procps \ 43 | gpg 44 | 45 | RUN ln -s /usr/lib/go-1.15/bin/go /usr/bin/go 46 | 47 | # Copy the script 48 | COPY PublishLaunchpad.sh /PublishLaunchpad.sh 49 | RUN chmod 777 /PublishLaunchpad.sh 50 | 51 | ARG USER 52 | ARG UID 53 | ARG GID 54 | 55 | # Configure git 56 | RUN mkdir -p /home/${USER} &&\ 57 | chmod 770 /home/${USER} && \ 58 | chown ${UID}:${GID} /home/${USER} 59 | 60 | RUN addgroup --gid ${GID} ${USER} &&\ 61 | adduser --system --quiet --home /home/${USER} --gid ${GID} --uid ${UID} --gecos "builder" ${USER} || true -------------------------------------------------------------------------------- /build/LaunchpadPublish/Dockerfile.focal: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishLaunchpadInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./PublishLaunchpad.sh when this container get started 9 | # ###################################################################################### 10 | 11 | # Use the packages target version (focal = ubuntu 20.04) as base image 12 | FROM ubuntu:focal 13 | 14 | # Setup the system and install needed packages 15 | ENV DEBIAN_FRONTEND="noninteractive" 16 | ENV TZ="Europe/London" 17 | RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget \ 18 | curl \ 19 | libc6 \ 20 | golang-1.16 \ 21 | gzip \ 22 | ronn\ 23 | debhelper \ 24 | golang-any \ 25 | golang-github-go-kit-kit-dev \ 26 | golang-github-prometheus-client-golang-dev \ 27 | golang-github-prometheus-common-dev \ 28 | golang-gopkg-alecthomas-kingpin.v2-dev \ 29 | golang-github-shirou-gopsutil-dev \ 30 | dh-golang \ 31 | debhelper \ 32 | dh-make \ 33 | lintian \ 34 | git-buildpackage \ 35 | git \ 36 | openssh-client \ 37 | procps \ 38 | gpg 39 | 40 | # Copy the script 41 | COPY PublishLaunchpad.sh /PublishLaunchpad.sh 42 | RUN chmod 777 /PublishLaunchpad.sh 43 | 44 | ARG USER 45 | ARG UID 46 | ARG GID 47 | 48 | # Configure git 49 | RUN mkdir -p /home/${USER} &&\ 50 | chmod 770 /home/${USER} && \ 51 | chown ${UID}:${GID} /home/${USER} 52 | 53 | RUN addgroup --gid ${GID} ${USER} &&\ 54 | adduser --system --quiet --home /home/${USER} --gid ${GID} --uid ${UID} --gecos "builder" ${USER} || true -------------------------------------------------------------------------------- /build/LaunchpadPublish/Dockerfile.jammy: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishLaunchpadInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./PublishLaunchpad.sh when this container get started 9 | # ###################################################################################### 10 | 11 | # Use the packages target version (jammy = ubuntu 22.04) as base image 12 | FROM ubuntu:jammy 13 | 14 | # Setup the system and install needed packages 15 | ENV DEBIAN_FRONTEND="noninteractive" 16 | ENV TZ="Europe/London" 17 | RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget \ 18 | curl \ 19 | libc6 \ 20 | golang-1.18 \ 21 | gzip \ 22 | ronn\ 23 | debhelper \ 24 | golang-any \ 25 | golang-github-go-kit-kit-dev \ 26 | golang-github-prometheus-client-golang-dev \ 27 | golang-github-prometheus-common-dev \ 28 | golang-gopkg-alecthomas-kingpin.v2-dev \ 29 | golang-github-shirou-gopsutil-dev \ 30 | dh-golang \ 31 | debhelper \ 32 | dh-make \ 33 | lintian \ 34 | git-buildpackage \ 35 | git \ 36 | openssh-client \ 37 | procps \ 38 | gpg 39 | 40 | # Copy the script 41 | COPY PublishLaunchpad.sh /PublishLaunchpad.sh 42 | RUN chmod 777 /PublishLaunchpad.sh 43 | 44 | ARG USER 45 | ARG UID 46 | ARG GID 47 | 48 | RUN mkdir -p /home/${USER} &&\ 49 | chmod 770 /home/${USER} && \ 50 | chown ${UID}:${GID} /home/${USER} 51 | 52 | RUN addgroup --gid ${GID} ${USER} &&\ 53 | adduser --system --quiet --home /home/${USER} --gid ${GID} --uid ${UID} --gecos "builder" ${USER} || true 54 | -------------------------------------------------------------------------------- /build/LaunchpadPublish/Dockerfile.kinetic: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishLaunchpadInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./PublishLaunchpad.sh when this container get started 9 | # ###################################################################################### 10 | 11 | # Use the packages target version (kinetic = ubuntu 22.10) as base image 12 | FROM ubuntu:kinetic 13 | 14 | # Setup the system and install needed packages 15 | ENV DEBIAN_FRONTEND="noninteractive" 16 | ENV TZ="Europe/London" 17 | RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget \ 18 | curl \ 19 | libc6 \ 20 | golang-1.19 \ 21 | gzip \ 22 | ronn\ 23 | debhelper \ 24 | golang-any \ 25 | golang-github-go-kit-kit-dev \ 26 | golang-github-prometheus-client-golang-dev \ 27 | golang-github-prometheus-common-dev \ 28 | golang-gopkg-alecthomas-kingpin.v2-dev \ 29 | golang-github-shirou-gopsutil-dev \ 30 | dh-golang \ 31 | debhelper \ 32 | dh-make \ 33 | lintian \ 34 | git-buildpackage \ 35 | git \ 36 | openssh-client \ 37 | procps \ 38 | gpg 39 | 40 | # Copy the script 41 | COPY PublishLaunchpad.sh /PublishLaunchpad.sh 42 | RUN chmod 777 /PublishLaunchpad.sh 43 | 44 | ARG USER 45 | ARG UID 46 | ARG GID 47 | 48 | RUN mkdir -p /home/${USER} &&\ 49 | chmod 770 /home/${USER} && \ 50 | chown ${UID}:${GID} /home/${USER} 51 | 52 | RUN addgroup --gid ${GID} ${USER} &&\ 53 | adduser --system --quiet --home /home/${USER} --gid ${GID} --uid ${UID} --gecos "builder" ${USER} || true 54 | -------------------------------------------------------------------------------- /build/LaunchpadPublish/Dockerfile.lunar: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishLaunchpadInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./PublishLaunchpad.sh when this container get started 9 | # ###################################################################################### 10 | 11 | # Use the packages target version (lunar = ubuntu 23.04) as base image 12 | FROM ubuntu:lunar 13 | 14 | # Setup the system and install needed packages 15 | ENV DEBIAN_FRONTEND="noninteractive" 16 | ENV TZ="Europe/London" 17 | RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget \ 18 | curl \ 19 | libc6 \ 20 | golang-1.20 \ 21 | gzip \ 22 | ronn\ 23 | debhelper \ 24 | golang-any \ 25 | golang-github-go-kit-kit-dev \ 26 | golang-github-prometheus-client-golang-dev \ 27 | golang-github-prometheus-common-dev \ 28 | golang-gopkg-alecthomas-kingpin.v2-dev \ 29 | golang-github-shirou-gopsutil-dev \ 30 | dh-golang \ 31 | debhelper \ 32 | dh-make \ 33 | lintian \ 34 | git-buildpackage \ 35 | git \ 36 | openssh-client \ 37 | procps \ 38 | gpg 39 | 40 | # Copy the script 41 | COPY PublishLaunchpad.sh /PublishLaunchpad.sh 42 | RUN chmod 777 /PublishLaunchpad.sh 43 | 44 | ARG USER 45 | ARG UID 46 | ARG GID 47 | 48 | RUN mkdir -p /home/${USER} &&\ 49 | chmod 770 /home/${USER} && \ 50 | chown ${UID}:${GID} /home/${USER} 51 | 52 | RUN addgroup --gid ${GID} ${USER} &&\ 53 | adduser --system --quiet --home /home/${USER} --gid ${GID} --uid ${UID} --gecos "builder" ${USER} || true 54 | 55 | RUN id ${UID} && ls -l /home/ 56 | -------------------------------------------------------------------------------- /build/LaunchpadPublish/Dockerfile.mantic: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishLaunchpadInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./PublishLaunchpad.sh when this container get started 9 | # ###################################################################################### 10 | 11 | # Use the packages target version (mantic = ubuntu 23.10) as base image 12 | FROM ubuntu:mantic 13 | 14 | # Setup the system and install needed packages 15 | ENV DEBIAN_FRONTEND="noninteractive" 16 | ENV TZ="Europe/London" 17 | RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget \ 18 | curl \ 19 | libc6 \ 20 | golang-1.21 \ 21 | gzip \ 22 | ronn\ 23 | debhelper \ 24 | golang-any \ 25 | golang-github-go-kit-kit-dev \ 26 | golang-github-prometheus-client-golang-dev \ 27 | golang-github-prometheus-common-dev \ 28 | golang-gopkg-alecthomas-kingpin.v2-dev \ 29 | golang-github-shirou-gopsutil-dev \ 30 | dh-golang \ 31 | debhelper \ 32 | dh-make \ 33 | lintian \ 34 | git-buildpackage \ 35 | git \ 36 | openssh-client \ 37 | procps \ 38 | gpg 39 | 40 | # Copy the script 41 | COPY PublishLaunchpad.sh /PublishLaunchpad.sh 42 | RUN chmod 777 /PublishLaunchpad.sh 43 | 44 | ARG USER 45 | ARG UID 46 | ARG GID 47 | 48 | RUN mkdir -p /home/${USER} &&\ 49 | chmod 770 /home/${USER} && \ 50 | chown ${UID}:${GID} /home/${USER} 51 | 52 | RUN addgroup --gid ${GID} ${USER} &&\ 53 | adduser --system --quiet --home /home/${USER} --gid ${GID} --uid ${UID} --gecos "builder" ${USER} || true 54 | 55 | RUN id ${UID} && ls -l /home/ 56 | -------------------------------------------------------------------------------- /build/LaunchpadPublish/Dockerfile.noble: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishLaunchpadInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./PublishLaunchpad.sh when this container get started 9 | # ###################################################################################### 10 | 11 | # Use the packages target version (noble = ubuntu 24.04) as base image 12 | FROM ubuntu:noble 13 | 14 | # Setup the system and install needed packages 15 | ENV DEBIAN_FRONTEND="noninteractive" 16 | ENV TZ="Europe/London" 17 | RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget \ 18 | curl \ 19 | libc6 \ 20 | golang-1.22 \ 21 | gzip \ 22 | ronn\ 23 | debhelper \ 24 | golang-any \ 25 | golang-github-go-kit-kit-dev \ 26 | golang-github-prometheus-client-golang-dev \ 27 | golang-github-prometheus-common-dev \ 28 | golang-gopkg-alecthomas-kingpin.v2-dev \ 29 | golang-github-shirou-gopsutil-dev \ 30 | dh-golang \ 31 | debhelper \ 32 | dh-make \ 33 | lintian \ 34 | git-buildpackage \ 35 | git \ 36 | openssh-client \ 37 | procps \ 38 | gpg 39 | 40 | # Copy the script 41 | COPY PublishLaunchpad.sh /PublishLaunchpad.sh 42 | RUN chmod 777 /PublishLaunchpad.sh 43 | 44 | ARG USER 45 | ARG UID 46 | ARG GID 47 | 48 | RUN mkdir -p /home/${USER} &&\ 49 | chmod 770 /home/${USER} && \ 50 | chown ${UID}:${GID} /home/${USER} 51 | 52 | RUN addgroup --gid ${GID} ${USER} &&\ 53 | adduser --system --quiet --home /home/${USER} --gid ${GID} --uid ${UID} --gecos "builder" ${USER} || true 54 | 55 | RUN id ${UID} && ls -l /home/ 56 | -------------------------------------------------------------------------------- /build/LaunchpadPublish/Dockerfile.oracular: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishLaunchpadInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./PublishLaunchpad.sh when this container get started 9 | # ###################################################################################### 10 | 11 | # Use the packages target version (noble = ubuntu 24.04) as base image 12 | FROM ubuntu:oracular 13 | 14 | # Setup the system and install needed packages 15 | ENV DEBIAN_FRONTEND="noninteractive" 16 | ENV TZ="Europe/London" 17 | RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget \ 18 | curl \ 19 | libc6 \ 20 | golang-1.23 \ 21 | gzip \ 22 | ronn\ 23 | debhelper \ 24 | golang-any \ 25 | golang-github-go-kit-kit-dev \ 26 | golang-github-prometheus-client-golang-dev \ 27 | golang-github-prometheus-common-dev \ 28 | golang-gopkg-alecthomas-kingpin.v2-dev \ 29 | golang-github-shirou-gopsutil-dev \ 30 | dh-golang \ 31 | debhelper \ 32 | dh-make \ 33 | lintian \ 34 | git-buildpackage \ 35 | git \ 36 | openssh-client \ 37 | procps \ 38 | gpg 39 | 40 | # Copy the script 41 | COPY PublishLaunchpad.sh /PublishLaunchpad.sh 42 | RUN chmod 777 /PublishLaunchpad.sh 43 | 44 | ARG USER 45 | ARG UID 46 | ARG GID 47 | 48 | RUN mkdir -p /home/${USER} &&\ 49 | chmod 770 /home/${USER} && \ 50 | chown ${UID}:${GID} /home/${USER} 51 | 52 | RUN addgroup --gid ${GID} ${USER} &&\ 53 | adduser --system --quiet --home /home/${USER} --gid ${GID} --uid ${UID} --gecos "builder" ${USER} || true 54 | 55 | RUN id ${UID} && ls -l /home/ 56 | -------------------------------------------------------------------------------- /build/LaunchpadPublish/Dockerfile.plucky: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishLaunchpadInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./PublishLaunchpad.sh when this container get started 9 | # ###################################################################################### 10 | 11 | # Use the packages target version (noble = ubuntu 24.04) as base image 12 | FROM ubuntu:plucky 13 | 14 | # Setup the system and install needed packages 15 | ENV DEBIAN_FRONTEND="noninteractive" 16 | ENV TZ="Europe/London" 17 | RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget \ 18 | curl \ 19 | libc6 \ 20 | golang-1.24 \ 21 | gzip \ 22 | ronn\ 23 | debhelper \ 24 | golang-any \ 25 | golang-github-go-kit-kit-dev \ 26 | golang-github-prometheus-client-golang-dev \ 27 | golang-github-prometheus-common-dev \ 28 | golang-gopkg-alecthomas-kingpin.v2-dev \ 29 | golang-github-shirou-gopsutil-dev \ 30 | dh-golang \ 31 | debhelper \ 32 | dh-make \ 33 | lintian \ 34 | git-buildpackage \ 35 | git \ 36 | openssh-client \ 37 | procps \ 38 | gpg 39 | 40 | # Copy the script 41 | COPY PublishLaunchpad.sh /PublishLaunchpad.sh 42 | RUN chmod 777 /PublishLaunchpad.sh 43 | 44 | ARG USER 45 | ARG UID 46 | ARG GID 47 | 48 | RUN mkdir -p /home/${USER} &&\ 49 | chmod 770 /home/${USER} && \ 50 | chown ${UID}:${GID} /home/${USER} 51 | 52 | RUN addgroup --gid ${GID} ${USER} &&\ 53 | adduser --system --quiet --home /home/${USER} --gid ${GID} --uid ${UID} --gecos "builder" ${USER} || true 54 | 55 | RUN id ${UID} && ls -l /home/ 56 | -------------------------------------------------------------------------------- /build/PrepareRelease.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ################################################################################################################ 3 | # Copyright 2021 by tobi@backfrak.de. All 4 | # rights reserved. Use of this source code is governed 5 | # by a BSD-style license that can be found in the 6 | # LICENSE file. 7 | # ################################################################################################################ 8 | # Script to create a release branch. 9 | # ################################################################################################################ 10 | 11 | # ################################################################################################################ 12 | # function definition 13 | # ################################################################################################################ 14 | function print_usage() { 15 | echo "Usage: $0 options" 16 | echo "-help Print this help" 17 | echo "This script will do all needed steps to do a new samba_exporter release localy." 18 | echo "And ask in the end if the result should be published on GutHub" 19 | } 20 | 21 | # ################################################################################################################ 22 | # variable asigenment 23 | # ################################################################################################################ 24 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 25 | BRANCH_ROOT="$SCRIPT_DIR/.." 26 | LOG_DIR="$BRANCH_ROOT/logs" 27 | RELEASE_BASE_BRANCH="main" 28 | RELEASE_BRANCH_NAME_PREFIX="release/V" 29 | VERSION_MASTER_PATH="VersionMaster.txt" 30 | 31 | # ################################################################################################################ 32 | # functional code 33 | # ################################################################################################################ 34 | 35 | if [ "$1" == "-help" ]; then 36 | print_usage 37 | exit 0 38 | fi 39 | 40 | pushd "$BRANCH_ROOT" >> /dev/null 41 | 42 | actualBranch=$(git status -b -s) 43 | if [ $? != 0 ]; then 44 | echo "Error: Can not get branch information" 45 | popd 46 | exit -1 47 | fi 48 | 49 | statusLines=$(echo "$actualBranch" | wc -l) 50 | if [ "$statusLines" != "1" ]; then 51 | echo "Error: There are change files that are not checked in." 52 | popd 53 | exit -1 54 | fi 55 | 56 | if [[ $actualBranch == *"[ahead"* ]]; then 57 | echo "Error: Local repository is ahead of remote" 58 | popd 59 | exit -1 60 | fi 61 | 62 | expectedStatus="## $RELEASE_BASE_BRANCH...origin/$RELEASE_BASE_BRANCH" 63 | if [ "$expectedStatus" != "$actualBranch" ]; then 64 | echo "Error: Not running on $RELEASE_BASE_BRANCH branch" 65 | popd 66 | exit -1 67 | fi 68 | 69 | versionInfo=$(cat $VERSION_MASTER_PATH) 70 | releaseBranchName="$RELEASE_BRANCH_NAME_PREFIX$versionInfo" 71 | echo "Release Branch name with name \"$releaseBranchName\" will be created" 72 | git checkout -b "$releaseBranchName" 73 | if [ "$?" != "0" ]; then 74 | echo "Error while creating release branch \"$releaseBranchName\"" 75 | popd 76 | exit -1 77 | fi 78 | 79 | echo "Switch back to \"$RELEASE_BASE_BRANCH\" branch" 80 | git checkout "$RELEASE_BASE_BRANCH" 81 | if [ "$?" != "0" ]; then 82 | echo "Error while switching back to \"$RELEASE_BASE_BRANCH\"" 83 | popd 84 | exit -1 85 | fi 86 | 87 | IFS='.' read -r -a versionNumbersArray <<< "$versionInfo" 88 | actualMinorNumber=${versionNumbersArray[1]} 89 | nextMinorNumber=$(expr $actualMinorNumber + 1) 90 | echo "Actual version is: Major ${versionNumbersArray[0]}, Minor $actualMinorNumber," 91 | echo "Next version is: Major ${versionNumbersArray[0]}, Minor $nextMinorNumber," 92 | nextVersionInfo="${versionNumbersArray[0]}.$nextMinorNumber" 93 | echo "Set new version $nextVersionInfo" 94 | echo -n "$nextVersionInfo" > $VERSION_MASTER_PATH 95 | 96 | 97 | echo "Commit the changed version master" 98 | git commit -a -m "Update version number master to $nextVersionInfo" 99 | if [ "$?" != "0" ]; then 100 | echo "Error while commit version number master to \"$RELEASE_BASE_BRANCH\"" 101 | popd 102 | exit -1 103 | fi 104 | git status 105 | 106 | echo "You want to push this changes now? (yes|no)" 107 | read answer 108 | if [ "$answer" != "yes" ]; then 109 | echo "Push aborted" 110 | popd 111 | exit 0 112 | fi 113 | git push origin "$RELEASE_BASE_BRANCH" 114 | if [ "$?" != "0" ]; then 115 | echo "Error while push \"$RELEASE_BASE_BRANCH\" to origin" 116 | popd 117 | exit -1 118 | fi 119 | 120 | git push origin "$releaseBranchName" 121 | if [ "$?" != "0" ]; then 122 | echo "Error while push \"$releaseBranchName\" to origin" 123 | popd 124 | exit -1 125 | fi 126 | 127 | popd >> /dev/null 128 | exit 0 129 | -------------------------------------------------------------------------------- /build/additional-pages/Dockerfile: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishLaunchpadInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./PublishLaunchpad.sh when this container get started 9 | # ###################################################################################### 10 | 11 | # Use the packages target version (focal = ubuntu 20.04) as base image 12 | FROM debian:bookworm 13 | 14 | # Setup the system and install needed packages 15 | ENV DEBIAN_FRONTEND="noninteractive" 16 | ENV TZ="Europe/London" 17 | RUN apt-get update && apt-get dist-upgrade -y && apt-get install -y wget \ 18 | curl \ 19 | git \ 20 | reprepro \ 21 | createrepo-c \ 22 | gpg 23 | 24 | # Copy the script 25 | COPY UpdatePagesRepo.sh /UpdatePagesRepo.sh 26 | RUN chmod 770 /UpdatePagesRepo.sh 27 | 28 | # Configure git 29 | RUN git config --global user.name "Tobias Zellner" && \ 30 | git config --global user.email imker@bienekaefig.de -------------------------------------------------------------------------------- /build/go.mod: -------------------------------------------------------------------------------- 1 | module tobi.backfrak.de/samba_exporter-testconvert 2 | 3 | go 1.23 4 | 5 | require github.com/tebeka/go2xunit v1.4.10 6 | 7 | 8 | -------------------------------------------------------------------------------- /build/go.sum: -------------------------------------------------------------------------------- 1 | github.com/tebeka/go2xunit v1.4.10 h1:0UO+9YoLpXTZ0DL9XbTmIIibgmKBGiwroo8uhFMSyR0= 2 | github.com/tebeka/go2xunit v1.4.10/go.mod h1:wmc9jKT7KlU4QLU6DNTaIXNnYNOjKKNlp6mjOS0UrqY= 3 | -------------------------------------------------------------------------------- /build/pages/mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: Samba Exporter - A prometheus exporter for the samba file server 2 | site_url: https://imker25.github.io/samba_exporter/ 3 | docs_dir: ./../../docs 4 | repo_url: https://github.com/imker25/samba_exporter 5 | repo_name: samba_exporter 6 | edit_uri: edit/main/docs/ 7 | site_description: Documentaion for Samba Exporter - A prometheus exporter for statistic data of the samba file server 8 | copyright: Apache-2.0 License 9 | 10 | theme: 11 | name: material 12 | locale: en 13 | highlightjs: true 14 | logo: ./assets/samba-exporter.icon.svg 15 | features: 16 | - navigation.expand 17 | - navigation.tracking 18 | - toc.integrate 19 | - navigation.top 20 | palette: 21 | scheme: slate 22 | primary: grey 23 | accent: light blue 24 | 25 | markdown_extensions: 26 | toc: 27 | permalink: true 28 | admonition: {} 29 | 30 | plugins: 31 | - search: 32 | - mermaid2: 33 | - git-revision-date: 34 | 35 | extra: 36 | homepage: https://imker25.github.io/samba_exporter/Index 37 | 38 | nav: 39 | - Start Page: 'Index.md' 40 | - Installation: 41 | - Supported Versions: Installation/SupportedVersions.md 42 | - Installation Guide: Installation/InstallationGuide.md 43 | - Users: 44 | - User Guide: UserDocs/UserGuide.md 45 | - Service Integration: UserDocs/ServiceIntegration.md 46 | - Concept: UserDocs/Concept.md 47 | - Developers: 48 | - Developer Guide: DeveloperDocs/Compile.md 49 | - Developer Hints: DeveloperDocs/Hints.md 50 | - Release Process: DeveloperDocs/ActionsAndReleases.md 51 | - Source: 'https://github.com/imker25/samba_exporter' 52 | - Issues: https://github.com/imker25/samba_exporter/issues -------------------------------------------------------------------------------- /build/pages/requirements.txt: -------------------------------------------------------------------------------- 1 | # Direct dependencies 2 | jinja2>=2.11.1 3 | markdown>=3.2 4 | mkdocs>=1.2.3 5 | mkdocs-material-extensions>=1.0 6 | pygments>=2.10 7 | pymdown-extensions>=9.0 8 | mkdocs-mermaid2-plugin>=0.5.2 9 | mkdocs-material>=7.3.6 10 | mkdocs-macros-plugin>=0.6.3 11 | mkdocs-git-revision-date-plugin>=0.3.2 -------------------------------------------------------------------------------- /build/rpm-build/BuildInDocker.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ###################################################################################### 3 | # Copyright 2022 by tobi@backfrak.de. All 4 | # rights reserved. Use of this source code is governed 5 | # by a BSD-style license that can be found in the 6 | # LICENSE file. 7 | # ###################################################################################### 8 | # Script to build and test the project in a fedora container with creating a binary rpm at the end 9 | 10 | # ################################################################################################################ 11 | # variable asigenment 12 | # ################################################################################################################ 13 | projcetRoot=/build_area 14 | 15 | # ################################################################################################################ 16 | # functional code 17 | # ################################################################################################################ 18 | echo "" 19 | echo "# ###################################################################" 20 | echo "Build in container - started" 21 | echo "# ###################################################################" 22 | if [ ! -d "$projcetRoot" ]; then 23 | echo "Error: Can not find the sources dir '$projcetRoot'" 24 | exit 1 25 | fi 26 | 27 | echo "Ensure ./build.sh can use the sources" 28 | echo "git config --global --add safe.directory /build_area" 29 | git config --global --add safe.directory /build_area 30 | 31 | pushd "$projcetRoot" 32 | 33 | echo "" 34 | echo "# ###################################################################" 35 | echo "Compile and unit test with ./build.sh" 36 | echo "# ###################################################################" 37 | ./build.sh test preparePack 38 | if [ "$?" != "0" ]; then 39 | echo "Error: Compile and test run failed" 40 | popd 41 | exit 1 42 | fi 43 | 44 | echo "" 45 | echo "# ###################################################################" 46 | echo "Create the man pages" 47 | echo "# ###################################################################" 48 | ./build/CreateManPage.sh 49 | if [ "$?" != "0" ]; then 50 | echo "Error: Man page creation failed" 51 | popd 52 | exit 1 53 | fi 54 | 55 | echo "" 56 | echo "# ###################################################################" 57 | echo "Run the integration tests" 58 | echo "# ###################################################################" 59 | ./test/integrationTest/scripts/RunIntegrationTests.sh 60 | if [ "$?" != "0" ]; then 61 | echo "Error: Integration tests failed" 62 | popd 63 | exit 1 64 | fi 65 | 66 | echo "" 67 | echo "# ###################################################################" 68 | echo "Prepare for rpm packaging" 69 | echo "# ###################################################################" 70 | rpmdev-setuptree 71 | rpmVersion=$(cat ./logs/ShortVersion.txt) 72 | fullVersion=$(cat ./logs/PackageName.txt) 73 | if [ "$rpmVersion" == "" ]; then 74 | echo "Error: Can not read the package version from './logs/ShortVersion.txt'" 75 | fi 76 | if [ "$fullVersion" == "" ]; then 77 | echo "Error: Can not read the full version from './logs/PackageName.txt'" 78 | fi 79 | echo "RPM Version will be: '$rpmVersion'" 80 | mkdir -pv "$HOME/rpmbuild/PREBINROOT/" 81 | mv -v "./tmp/${fullVersion}/"* "$HOME/rpmbuild/PREBINROOT/" 82 | pushd "$HOME/rpmbuild/" 83 | sed -i "s/Version: x.x.x/Version: $rpmVersion/g" ./PREBINROOT/samba-exporter.spec 84 | mv -v ./PREBINROOT/samba-exporter.spec ./SPECS/samba-exporter.spec 85 | 86 | echo "" 87 | echo "# ###################################################################" 88 | echo "Run rpm packaging" 89 | echo "# ###################################################################" 90 | rpmbuild -bb ./SPECS/samba-exporter.spec 91 | if [ "$?" != "0" ]; then 92 | echo "Error: RPM creation failed" 93 | popd 94 | popd 95 | exit 1 96 | fi 97 | popd 98 | 99 | if [ -f "$HOME/samba-exporter-${rpmVersion}-1.x86_64.rpm" ]; then 100 | mv -v "$HOME/samba-exporter-${rpmVersion}-1.x86_64.rpm" "./bin/" 101 | else 102 | echo "Error: Can not find the package file '$HOME/samba-exporter-${rpmVersion}-1.x86_64.rpm'" 103 | popd 104 | exit 1 105 | fi 106 | 107 | popd 108 | 109 | echo "" 110 | echo "# ###################################################################" 111 | echo "Build in container - done" 112 | echo "# ###################################################################" 113 | exit 0 114 | -------------------------------------------------------------------------------- /build/rpm-build/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM fedora:41 2 | 3 | RUN yum -y update && \ 4 | yum clean all 5 | RUN yum -y install redhat-lsb \ 6 | rubygem-ronn-ng \ 7 | rpmdevtools \ 8 | rpmlint \ 9 | rpm-build \ 10 | gzip \ 11 | curl \ 12 | man-db \ 13 | binutils \ 14 | wget \ 15 | procps-ng \ 16 | golang && \ 17 | yum clean all 18 | 19 | COPY BuildInDocker.sh /BuildInDocker.sh 20 | 21 | ARG USER 22 | ARG UID 23 | ARG GID 24 | 25 | RUN chmod 777 /BuildInDocker.sh 26 | 27 | RUN mkdir -p /home/${USER} &&\ 28 | chmod 770 /home/${USER} && \ 29 | chown ${UID}:${GID} /home/${USER} && \ 30 | chmod 777 /var/lib/rpm/ -------------------------------------------------------------------------------- /build/rpm-publish/Dockerfile.fedora28: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishRpmInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./RpmPublish.sh when this container get started 9 | # ###################################################################################### 10 | 11 | FROM fedora:28 12 | 13 | RUN yum -y update && \ 14 | yum clean all 15 | RUN yum -y install redhat-lsb \ 16 | ruby \ 17 | ruby-devel \ 18 | rubygems \ 19 | rpmdevtools \ 20 | rpmlint \ 21 | rpm-build \ 22 | rpm-sign \ 23 | gzip \ 24 | curl \ 25 | man-db \ 26 | binutils \ 27 | wget \ 28 | gnupg \ 29 | procps-ng \ 30 | git && \ 31 | yum clean all 32 | 33 | # Install golang 34 | RUN mkdir -p /root && \ 35 | cd /root && \ 36 | wget https://go.dev/dl/go1.23.4.linux-amd64.tar.gz && \ 37 | rm -rf /usr/local/go && \ 38 | tar -C /usr/local -xzf go1.23.4.linux-amd64.tar.gz &&\ 39 | ln -s /usr/local/go/bin/go /usr/bin/go && \ 40 | go version 41 | 42 | # Install ronn 43 | RUN gem install --no-user-install ronn && \ 44 | ln -s /usr/local/share/gems/gems/ronn-0.7.3/bin/ronn /usr/bin/ronn 45 | 46 | ARG USER 47 | ARG UID 48 | ARG GID 49 | 50 | # Add publish script 51 | COPY RpmPublish.sh /RpmPublish.sh 52 | RUN chmod 777 /RpmPublish.sh 53 | 54 | # Add the user that will run the build 55 | RUN mkdir -p /home/${USER} &&\ 56 | chmod 770 /home/${USER} && \ 57 | chown ${UID}:${GID} /home/${USER} && \ 58 | chmod 777 /var/lib/rpm/ 59 | 60 | -------------------------------------------------------------------------------- /build/rpm-publish/Dockerfile.fedora35: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishRpmInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./RpmPublish.sh when this container get started 9 | # ###################################################################################### 10 | 11 | FROM fedora:35 12 | 13 | RUN dnf -y update && \ 14 | dnf install -y 'dnf-command(builddep)' \ 15 | redhat-lsb \ 16 | rubygem-ronn-ng \ 17 | rpmdevtools \ 18 | rpmlint \ 19 | rpm-build \ 20 | rpm-sign \ 21 | gzip \ 22 | curl \ 23 | man-db \ 24 | binutils \ 25 | wget \ 26 | git \ 27 | go-rpm-macros \ 28 | openssh-clients \ 29 | copr-cli \ 30 | procps-ng \ 31 | gnupg && \ 32 | dnf clean all 33 | 34 | COPY samba-exporter.from_source.spec /samba-exporter.from_source.spec 35 | 36 | RUN dnf builddep --spec /samba-exporter.from_source.spec -y && \ 37 | dnf clean all 38 | 39 | ARG USER 40 | ARG UID 41 | ARG GID 42 | 43 | 44 | # Add publish script 45 | COPY RpmPublish.sh /RpmPublish.sh 46 | RUN chmod 777 /RpmPublish.sh 47 | 48 | RUN mkdir -p /home/${USER} &&\ 49 | chmod 770 /home/${USER} && \ 50 | chown ${UID}:${GID} /home/${USER} && \ 51 | chmod 777 /var/lib/rpm/ 52 | 53 | -------------------------------------------------------------------------------- /build/rpm-publish/Dockerfile.fedora36: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishRpmInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./RpmPublish.sh when this container get started 9 | # ###################################################################################### 10 | 11 | FROM fedora:36 12 | 13 | RUN dnf -y update && \ 14 | dnf install -y 'dnf-command(builddep)' \ 15 | redhat-lsb \ 16 | rubygem-ronn-ng \ 17 | rpmdevtools \ 18 | rpmlint \ 19 | rpm-build \ 20 | rpm-sign \ 21 | gzip \ 22 | curl \ 23 | man-db \ 24 | binutils \ 25 | wget \ 26 | git \ 27 | go-rpm-macros \ 28 | openssh-clients \ 29 | copr-cli \ 30 | procps-ng \ 31 | gnupg && \ 32 | dnf clean all 33 | 34 | COPY samba-exporter.from_source.spec /samba-exporter.from_source.spec 35 | 36 | RUN dnf builddep --spec /samba-exporter.from_source.spec -y && \ 37 | dnf clean all 38 | 39 | ARG USER 40 | ARG UID 41 | ARG GID 42 | 43 | # Add publish script 44 | COPY RpmPublish.sh /RpmPublish.sh 45 | RUN chmod 777 /RpmPublish.sh 46 | 47 | RUN mkdir -p /home/${USER} &&\ 48 | chmod 770 /home/${USER} && \ 49 | chown ${UID}:${GID} /home/${USER} && \ 50 | chmod 777 /var/lib/rpm/ 51 | 52 | -------------------------------------------------------------------------------- /build/rpm-publish/Dockerfile.fedora37: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishRpmInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./RpmPublish.sh when this container get started 9 | # ###################################################################################### 10 | 11 | FROM fedora:37 12 | 13 | RUN dnf -y update && \ 14 | dnf install -y 'dnf-command(builddep)' \ 15 | redhat-lsb \ 16 | rubygem-ronn-ng \ 17 | rpmdevtools \ 18 | rpmlint \ 19 | rpm-build \ 20 | rpm-sign \ 21 | gzip \ 22 | curl \ 23 | man-db \ 24 | binutils \ 25 | wget \ 26 | git \ 27 | go-rpm-macros \ 28 | openssh-clients \ 29 | copr-cli \ 30 | procps-ng \ 31 | gnupg && \ 32 | dnf clean all 33 | 34 | COPY samba-exporter.from_source.spec /samba-exporter.from_source.spec 35 | 36 | RUN dnf builddep --spec /samba-exporter.from_source.spec -y && \ 37 | dnf clean all 38 | 39 | ARG USER 40 | ARG UID 41 | ARG GID 42 | 43 | # Add publish script 44 | COPY RpmPublish.sh /RpmPublish.sh 45 | RUN chmod 777 /RpmPublish.sh 46 | 47 | RUN mkdir -p /home/${USER} &&\ 48 | chmod 770 /home/${USER} && \ 49 | chown ${UID}:${GID} /home/${USER} && \ 50 | chmod 777 /var/lib/rpm/ 51 | 52 | -------------------------------------------------------------------------------- /build/rpm-publish/Dockerfile.fedora38: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishRpmInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./RpmPublish.sh when this container get started 9 | # ###################################################################################### 10 | 11 | FROM fedora:38 12 | 13 | RUN dnf -y update && \ 14 | dnf install -y 'dnf-command(builddep)' \ 15 | redhat-lsb \ 16 | rubygem-ronn-ng \ 17 | rpmdevtools \ 18 | rpmlint \ 19 | rpm-build \ 20 | rpm-sign \ 21 | gzip \ 22 | curl \ 23 | man-db \ 24 | binutils \ 25 | wget \ 26 | git \ 27 | go-rpm-macros \ 28 | openssh-clients \ 29 | copr-cli \ 30 | procps-ng \ 31 | gnupg && \ 32 | dnf clean all 33 | 34 | COPY samba-exporter.from_source.spec /samba-exporter.from_source.spec 35 | 36 | RUN dnf builddep --spec /samba-exporter.from_source.spec -y && \ 37 | dnf clean all 38 | 39 | ARG USER 40 | ARG UID 41 | ARG GID 42 | 43 | # Add publish script 44 | COPY RpmPublish.sh /RpmPublish.sh 45 | RUN chmod 777 /RpmPublish.sh 46 | 47 | RUN mkdir -p /home/${USER} &&\ 48 | chmod 770 /home/${USER} && \ 49 | chown ${UID}:${GID} /home/${USER} && \ 50 | chmod 777 /var/lib/rpm/ 51 | 52 | -------------------------------------------------------------------------------- /build/rpm-publish/Dockerfile.fedora39: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishRpmInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./RpmPublish.sh when this container get started 9 | # ###################################################################################### 10 | 11 | FROM fedora:39 12 | 13 | RUN dnf -y update && \ 14 | dnf install -y 'dnf-command(builddep)' \ 15 | redhat-lsb \ 16 | rubygem-ronn-ng \ 17 | rpmdevtools \ 18 | rpmlint \ 19 | rpm-build \ 20 | rpm-sign \ 21 | gzip \ 22 | curl \ 23 | man-db \ 24 | binutils \ 25 | wget \ 26 | git \ 27 | go-rpm-macros \ 28 | openssh-clients \ 29 | copr-cli \ 30 | procps-ng \ 31 | gnupg && \ 32 | dnf clean all 33 | 34 | COPY samba-exporter.from_source.spec /samba-exporter.from_source.spec 35 | 36 | RUN dnf builddep --spec /samba-exporter.from_source.spec -y && \ 37 | dnf clean all 38 | 39 | ARG USER 40 | ARG UID 41 | ARG GID 42 | 43 | # Add publish script 44 | COPY RpmPublish.sh /RpmPublish.sh 45 | RUN chmod 777 /RpmPublish.sh 46 | 47 | RUN mkdir -p /home/${USER} &&\ 48 | chmod 770 /home/${USER} && \ 49 | chown ${UID}:${GID} /home/${USER} && \ 50 | chmod 777 /var/lib/rpm/ 51 | 52 | -------------------------------------------------------------------------------- /build/rpm-publish/Dockerfile.fedora40: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishRpmInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./RpmPublish.sh when this container get started 9 | # ###################################################################################### 10 | 11 | FROM fedora:40 12 | 13 | RUN dnf -y update && \ 14 | dnf install -y 'dnf-command(builddep)' \ 15 | redhat-lsb \ 16 | rubygem-ronn-ng \ 17 | rpmdevtools \ 18 | rpmlint \ 19 | rpm-build \ 20 | rpm-sign \ 21 | gzip \ 22 | curl \ 23 | man-db \ 24 | binutils \ 25 | wget \ 26 | git \ 27 | go-rpm-macros \ 28 | openssh-clients \ 29 | copr-cli \ 30 | procps-ng \ 31 | gnupg && \ 32 | dnf clean all 33 | 34 | COPY samba-exporter.from_source.spec /samba-exporter.from_source.spec 35 | 36 | RUN dnf builddep --spec /samba-exporter.from_source.spec -y && \ 37 | dnf clean all 38 | 39 | ARG USER 40 | ARG UID 41 | ARG GID 42 | 43 | # Add publish script 44 | COPY RpmPublish.sh /RpmPublish.sh 45 | RUN chmod 777 /RpmPublish.sh 46 | 47 | RUN mkdir -p /home/${USER} &&\ 48 | chmod 770 /home/${USER} && \ 49 | chown ${UID}:${GID} /home/${USER} && \ 50 | chmod 777 /var/lib/rpm/ 51 | 52 | -------------------------------------------------------------------------------- /build/rpm-publish/Dockerfile.fedora41: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishRpmInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./RpmPublish.sh when this container get started 9 | # ###################################################################################### 10 | 11 | FROM fedora:41 12 | 13 | RUN dnf -y update && \ 14 | dnf install -y 'dnf-command(builddep)' \ 15 | redhat-lsb \ 16 | rubygem-ronn-ng \ 17 | rpmdevtools \ 18 | rpmlint \ 19 | rpm-build \ 20 | rpm-sign \ 21 | gzip \ 22 | curl \ 23 | man-db \ 24 | binutils \ 25 | wget \ 26 | git \ 27 | go-rpm-macros \ 28 | openssh-clients \ 29 | copr-cli \ 30 | procps-ng \ 31 | gnupg && \ 32 | dnf clean all 33 | 34 | COPY samba-exporter.from_source.spec /samba-exporter.from_source.spec 35 | 36 | RUN dnf builddep /samba-exporter.from_source.spec -y && \ 37 | dnf clean all 38 | 39 | ARG USER 40 | ARG UID 41 | ARG GID 42 | 43 | # Add publish script 44 | COPY RpmPublish.sh /RpmPublish.sh 45 | RUN chmod 777 /RpmPublish.sh 46 | 47 | RUN mkdir -p /home/${USER} &&\ 48 | chmod 770 /home/${USER} && \ 49 | chown ${UID}:${GID} /home/${USER} && \ 50 | chmod 777 /var/lib/rpm/ 51 | 52 | -------------------------------------------------------------------------------- /build/rpm-publish/Dockerfile.fedora42: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by ./../PublishRpmInDocker.sh to transfer the sources to the launchpad-ppa 8 | # The actual transformation is done by ./RpmPublish.sh when this container get started 9 | # ###################################################################################### 10 | 11 | FROM fedora:42 12 | 13 | RUN dnf -y update && \ 14 | dnf install -y 'dnf-command(builddep)' \ 15 | redhat-lsb \ 16 | rubygem-ronn-ng \ 17 | rpmdevtools \ 18 | rpmlint \ 19 | rpm-build \ 20 | rpm-sign \ 21 | gzip \ 22 | curl \ 23 | man-db \ 24 | binutils \ 25 | wget \ 26 | git \ 27 | go-rpm-macros \ 28 | openssh-clients \ 29 | copr-cli \ 30 | procps-ng \ 31 | gnupg && \ 32 | dnf clean all 33 | 34 | COPY samba-exporter.from_source.spec /samba-exporter.from_source.spec 35 | 36 | RUN dnf builddep /samba-exporter.from_source.spec -y && \ 37 | dnf clean all 38 | 39 | ARG USER 40 | ARG UID 41 | ARG GID 42 | 43 | # Add publish script 44 | COPY RpmPublish.sh /RpmPublish.sh 45 | RUN chmod 777 /RpmPublish.sh 46 | 47 | RUN mkdir -p /home/${USER} &&\ 48 | chmod 770 /home/${USER} && \ 49 | chown ${UID}:${GID} /home/${USER} && \ 50 | chmod 777 /var/lib/rpm/ 51 | 52 | -------------------------------------------------------------------------------- /build/workflow/go.mod: -------------------------------------------------------------------------------- 1 | module tobi.backfrak.de/samba-exporter-build 2 | 3 | go 1.23 4 | 5 | require github.com/magefile/mage v1.14.0 6 | 7 | require github.com/imker25/gobuildhelpers v0.1.4 8 | -------------------------------------------------------------------------------- /build/workflow/go.sum: -------------------------------------------------------------------------------- 1 | github.com/imker25/gobuildhelpers v0.1.4 h1:Kl/dYVK8EA2Pkz9SbK0jn9Xh5+o9Us2RO1bwuwJ0Eyw= 2 | github.com/imker25/gobuildhelpers v0.1.4/go.mod h1:+6D/dkCwauwTh/KmIZDcTDFVpcokMAZCXNLyckxBJFg= 3 | github.com/magefile/mage v1.14.0 h1:6QDX3g6z1YvJ4olPhT1wksUcSa/V0a1B+pJb73fBjyo= 4 | github.com/magefile/mage v1.14.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= 5 | -------------------------------------------------------------------------------- /build/workflow/mage.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "os" 10 | 11 | "github.com/magefile/mage/mage" 12 | ) 13 | 14 | func main() { os.Exit(mage.Main()) } 15 | -------------------------------------------------------------------------------- /docs/DeveloperDocs/Compile.md: -------------------------------------------------------------------------------- 1 | # Developer Guide 2 | 3 | This page shows you how to build, test and install the project manually. 4 | 5 | ## Build 6 | 7 | To build the project you need the following on your development machine. 8 | 9 | - [Go](https://golang.org/) Version 1.16.x or later 10 | - [Git](https://git-scm.com/) >= Version 2.30 11 | - [lsb_release](https://refspecs.linuxfoundation.org/LSB_3.0.0/LSB-PDA/LSB-PDA/lsbrelease.html) 12 | - [ronn](https://github.com/rtomayko/ronn) - Only in case you want to work on man pages 13 | 14 | To build the software change to the repositories directory and run: 15 | 16 | ```sh 17 | ./build.sh build 18 | ``` 19 | 20 | To figure out all the valid tasks, read `./build.sh -l` 21 | 22 | ## Create man pages 23 | 24 | To create the man pages out of the `*.ronn` source files in `src/man` run: 25 | 26 | ```sh 27 | build/CreateManPage.sh 28 | ``` 29 | 30 | ## Run Tests locally 31 | 32 | To execute the unit tests you can run: 33 | 34 | ```sh 35 | ./build.sh test 36 | ``` 37 | 38 | **Hint:** As always it is possible to combine the commands, e. g. `./build.sh build test` 39 | 40 | To execute the integration tests you can run: 41 | 42 | ```sh 43 | ./test/integrationTest/scripts/RunIntegrationTests.sh 44 | ``` 45 | 46 | ## Manual installation 47 | 48 | On your target machine, the samba server you want to monitor, you need [samba](https://www.samba.org/) and [systemd](https://www.freedesktop.org/wiki/Software/systemd/) installed. 49 | 50 | To build for manual installation run the following: 51 | 52 | ```sh 53 | ./build.sh preparePack 54 | build/CreateManPage.sh 55 | ``` 56 | 57 | For manual install on the `target` machine do the following copy after you build the project as shown above: 58 | 59 | ```sh 60 | rsync -avr --exclude 'DEBIAN' --exclude 'samba-exporter.spec' ./tmp/samba-exporter_/* root@:/ 61 | ``` 62 | 63 | Now login to your target machine and run the commands below to enable the services and create the needed user and group: 64 | 65 | ```sh 66 | systemctl daemon-reload 67 | systemctl enable samba_statusd.service 68 | systemctl enable samba_exporter.service 69 | addgroup --system samba-exporter 70 | adduser --system --no-create-home --disabled-login samba-exporter 71 | adduser samba-exporter samba-exporter 72 | mandb # In case you created and copied the man pages as well 73 | ``` 74 | 75 | Finally you are abel to start the services: 76 | 77 | ```sh 78 | systemctl start samba_statusd.service 79 | systemctl start samba_exporter.service 80 | ``` 81 | 82 | ### Test installation 83 | 84 | Test the `samba_exporter` by requesting metrics with `curl`: 85 | 86 | ```sh 87 | curl http://127.0.0.1:9922/metrics 88 | ``` 89 | 90 | The output of this test should look something like this: 91 | 92 | ```txt 93 | # HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles. 94 | # TYPE go_gc_duration_seconds summary 95 | go_gc_duration_seconds{quantile="0"} 0 96 | ... 97 | # HELP promhttp_metric_handler_requests_in_flight Current number of scrapes being served. 98 | # TYPE promhttp_metric_handler_requests_in_flight gauge 99 | promhttp_metric_handler_requests_in_flight 1 100 | # HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code. 101 | # TYPE promhttp_metric_handler_requests_total counter 102 | promhttp_metric_handler_requests_total{code="200"} 0 103 | promhttp_metric_handler_requests_total{code="500"} 0 104 | promhttp_metric_handler_requests_total{code="503"} 0 105 | # HELP samba_client_count Number of clients using the samba server 106 | # TYPE samba_client_count gauge 107 | samba_client_count 0 108 | # HELP samba_individual_user_count The number of users connected to this samba server 109 | # TYPE samba_individual_user_count gauge 110 | samba_individual_user_count 0 111 | # HELP samba_locked_file_count Number of files locked by the samba server 112 | # TYPE samba_locked_file_count gauge 113 | samba_locked_file_count 0 114 | # HELP samba_pid_count Number of processes running by the samba server 115 | # TYPE samba_pid_count gauge 116 | samba_pid_count 0 117 | # HELP samba_satutsd_up 1 if the samba_statusd seems to be running 118 | # TYPE samba_satutsd_up gauge 119 | samba_satutsd_up 1 120 | # HELP samba_server_up 1 if the samba server seems to be running 121 | # TYPE samba_server_up gauge 122 | samba_server_up 1 123 | # HELP samba_share_count Number of shares used by clients of the samba server 124 | # TYPE samba_share_count gauge 125 | samba_share_count 0 126 | ``` 127 | -------------------------------------------------------------------------------- /docs/DeveloperDocs/Hints.md: -------------------------------------------------------------------------------- 1 | # Developer Hints 2 | 3 | ## VSCode Settings 4 | 5 | In case you want develop this software with [VS Code](https://code.visualstudio.com/) you need to add the repositories root folder to the **GOPATH** within the `VS Code Settings` to get golang extension and golang tools work, e. g.: 6 | 7 | ```json 8 | { 9 | "go.gopath": "${env:GOPATH}:${workspaceFolder}", 10 | } 11 | ``` 12 | 13 | ## Debugging 14 | 15 | For debugging the pipe communication you might want to use the `-test-mode` on `samba_statusd` and `samba_exporter`. 16 | 17 | **Remark:** Never use `-test-mode` on just one of the two programs. -------------------------------------------------------------------------------- /docs/Index.md: -------------------------------------------------------------------------------- 1 | # Samba Exporter 2 | 3 | A [prometheus exporter](https://prometheus.io/docs/instrumenting/exporters/) for statistic data of the [samba file server](https://www.samba.org/). 4 | 5 | ![Screenshot of dashboard for the samba service](./assets/Samba-Dashboard.png) 6 | 7 | It uses [smbstatus](https://www.samba.org/samba/docs/current/man-html/smbstatus.1.html) and the [proc fs](https://en.wikipedia.org/wiki/Procfs) to collect the data and converts the result into prometheus style data. 8 | The prometheus style data can be requested manually on port 9922 using a http client. Or a prometheus database sever can be configured to collect the data by scraping port 9922 on the samba server. 9 | 10 | ## Lear more 11 | 12 | - [User Guide](./UserDocs/UserGuide.md) 13 | - [Concept](./UserDocs/Concept.md) 14 | 15 | ## Next steps 16 | 17 | - [Installation](./Installation/InstallationGuide.md) 18 | - [Grafana Stack Integration](./UserDocs/ServiceIntegration.md) 19 | -------------------------------------------------------------------------------- /docs/Installation/InstallationGuide.md: -------------------------------------------------------------------------------- 1 | # Installation Guide 2 | 3 | Below you can find installation guides for the supported versions. 4 | 5 | ## Ubuntu Launchpad 6 | 7 | The **samba exporter** package for Ubuntu is published on [launchpad](https://launchpad.net/~imker/+archive/ubuntu/samba-exporter-ppa). To install from there do the following commands on any supported Ubuntu version: 8 | 9 | ```sh 10 | sudo add-apt-repository ppa:imker/samba-exporter-ppa 11 | sudo apt-get update 12 | sudo apt-get install samba-exporter 13 | ``` 14 | 15 | ## Debian 16 | 17 | The **samba exporter** package for Debian is published on the projects GitHub Page. To install execute the commands shown below as root: 18 | 19 | ```bash 20 | wget -qO - https://imker25.github.io/samba_exporter/repos/debian/archive.key | sudo apt-key add - 21 | echo "deb https://imker25.github.io/samba_exporter/repos/debian bullseye main" > /etc/apt/sources.list.d/samba-exporter.list 22 | apt-get update 23 | apt-get install samba-exporter 24 | ``` 25 | 26 | **Hint:** Change `bullseye` to `bookworm` in case you use Debian 12. 27 | 28 | ## Fedora 35 and later 29 | 30 | The **samba exporter** package for Fedora is published on [copr](https://copr.fedorainfracloud.org/coprs/imker25/samba-exporter/). To install from there do the following commands on any supported Fedora version: 31 | 32 | ```bash 33 | sudo dnf copr enable imker25/samba-exporter 34 | sudo dnf update 35 | sudo dnf install samba-exporter 36 | ``` 37 | 38 | ## RHEL 8 / CentOS 8 / CentOS Stream 8 / Fedora 28 39 | 40 | For Redhat Enterprise Linux 8 and all compatible distributions the **samba exporter** package is published on the projects GitHub Page. To install execute the commands shown below as root: 41 | 42 | ```bash 43 | wget -O /dev/shm/archive.key https://imker25.github.io/samba_exporter/repos/debian/archive.key 44 | rpm --import /dev/shm/archive.key 45 | dnf config-manager --add-repo https://imker25.github.io/samba_exporter/repos/rpm/fedora/releases/28/x86_64 46 | dnf update 47 | dnf install samba-exporter 48 | ``` 49 | 50 | ## RHEL 9 / CentOS Stream 9 / Fedora 35 51 | 52 | For Redhat Enterprise Linux 9 and all compatible distributions the **samba exporter** package is published on the projects GitHub Page. To install execute the commands shown below as root: 53 | 54 | ```bash 55 | wget -O /dev/shm/archive.key https://imker25.github.io/samba_exporter/repos/debian/archive.key 56 | rpm --import /dev/shm/archive.key 57 | dnf config-manager --add-repo https://imker25.github.io/samba_exporter/repos/rpm/fedora/releases/35/x86_64 58 | dnf update 59 | dnf install samba-exporter 60 | ``` 61 | 62 | ## GitHub Releases - For debian based distributions 63 | 64 | Install the [latest Release](https://github.com/imker25/samba_exporter/releases/latest) by downloading the debian package according to your distribution and version and installing it. For example: 65 | 66 | ```sh 67 | wget https://github.com/imker25/samba_exporter/releases/download/1.3.5-pre/samba-exporter_1.3.5-pre.ppa1.debian10_amd64.deb 68 | sudo dpkg --install ./samba-exporter_1.3.5-pre.ppa1.debian10_amd64.deb 69 | ``` 70 | 71 | **Hint:** Link and file name needs to be adapted to the latest release. 72 | 73 | It's also possible to download and install pre-releases from the GitHub this way. 74 | 75 | ## GitHub Releases - For RPM based distributions 76 | 77 | Install the [latest Release](https://github.com/imker25/samba_exporter/releases/latest) by downloading the rpm package according to your distribution and version and installing it. For example: 78 | 79 | ```sh 80 | wget https://github.com/imker25/samba_exporter/releases/download/1.12.5-pre/samba-exporter-1.12.5-1.fc35.x86_64.rpm 81 | sudo rpm -U samba-exporter-1.12.5-1.fc35.x86_64.rpm 82 | ``` 83 | 84 | **Hint:** Link and file name needs to be adapted to the latest release. 85 | 86 | It's also possible to download and install pre-releases from the GitHub this way. 87 | 88 | For manual installation see the [Developer Guide](../DeveloperDocs/Compile.md). 89 | -------------------------------------------------------------------------------- /docs/Installation/SupportedVersions.md: -------------------------------------------------------------------------------- 1 | # Supported Versions 2 | 3 | ## Debian based 4 | 5 | **Ubuntu:** 6 | 7 | | Version | Code Name | Supported | 8 | |---------|-----------|-----------| 9 | | Ubnutu 20.04 | Focal Fossa | no | 10 | | Ubnutu 21.04 | Hirsute Hippo | no | 11 | | Ubnutu 21.10 | Impish Indri | no | 12 | | Ubnutu 22.04 | Jammy Jellyfish | yes | 13 | | Ubnutu 22.10 | Kinetic Kudu | no | 14 | | Ubnutu 23.04 | Lunar Lobster | no | 15 | | Ubnutu 23.10 | Mantic Minotaur | no | 16 | | Ubnutu 24.04 | Noble Numbat | yes | 17 | | Ubnuntu 24.10 | Oracular Oriole | no | 18 | | Ubnuntu 25.04 | Plucky Puffin | yes | 19 | | Ubnuntu 25.10 | - | planed | 20 | 21 | --- 22 | 23 | **Debian:** 24 | 25 | | Version | Code Name | Supported | 26 | |---------|-----------|-----------| 27 | | Debian 10 | Buster | no | 28 | | Debian 11 | Bullseye | yes | 29 | | Debian 12 | Bookworm | yes | 30 | | Debian 13 | Trixie | planed | 31 | | Debian testing | Forky | no | 32 | 33 | ## RPM based 34 | 35 | **Fedora:** 36 | 37 | | Version | Release | Supported | 38 | |---------|-----------|-----------| 39 | | Fedora 28 | 2018-05-01 | yes | 40 | | Fedora 29 | 2018-10-30 | no | 41 | | Fedora 30 | 2019-04-29 | no | 42 | | Fedora 31 | 2019-10-29 | no | 43 | | Fedora 32 | 2020-04-28 | no | 44 | | Fedora 33 | 2020-10-28 | no | 45 | | Fedora 34 | 2021-04-27 | no | 46 | | Fedora 35 | 2021-11-02 | yes | 47 | | Fedora 36 | 2022-04-19 | no | 48 | | Fedora 37 | 2022-11-15 | no | 49 | | Fedora 38 | 2023-04-25 | no | 50 | | Fedora 39 | 2023-10-24 | no | 51 | | Fedora 40 | 2024-04-23 | no | 52 | | Fedora 41 | 2024-10-29 | yes | 53 | | Fedora 42 | 2025-04-22 | yes | 54 | | Fedora 43 | XXX | planed | 55 | 56 | --- 57 | 58 | **CentOS Stream:** 59 | 60 | | Version | Release | Supported | 61 | |---------|-----------|-----------| 62 | | CentOS Stream| 8 | yes | 63 | | CentOS Stream| 9 | yes | 64 | 65 | --- 66 | 67 | **Red Hat Enterprise Linux:** 68 | 69 | | Version | Release | Supported | 70 | |---------|-----------|-----------| 71 | | RHEL 8 | 2019-05-07 | yes | 72 | | RHEL 9 | 2022-05-19 | yes | 73 | 74 | --- 75 | -------------------------------------------------------------------------------- /docs/UserDocs/Concept.md: -------------------------------------------------------------------------------- 1 | # Concept 2 | 3 | Since the tool [smbstatus](https://www.samba.org/samba/docs/current/man-html/smbstatus.1.html) provided by the [samba](https://www.samba.org/) project can only run with elevated rights, and a [prometheus exporter](https://prometheus.io/docs/instrumenting/writing_exporters/) always exposes a public network endpoint, the samba_exporter package contains two services. 4 | 5 | - **samba_exporter**: The prometheus exporter service that exposes the public network endpoint for the prometheus server to collect the data running as non **privileged user** 6 | - **samba_statusd**: The service uses `smbstatus` to collect data and return it when requested running as **privileged user** 7 | 8 | Both services can communicate using a named pipe owned by a common group, see diagram below. 9 | 10 | ```mermaid 11 | %%{init: {'theme':'dark'}}%% 12 | sequenceDiagram 13 | participant samba_exporter 14 | participant request.pipe 15 | participant response.pipe 16 | participant samba_statusd 17 | samba_exporter->>request.pipe: Request status data 18 | loop 19 | samba_statusd ->> request.pipe: Check request data 20 | end 21 | samba_statusd ->> samba_statusd: Process request 22 | samba_statusd ->> response.pipe: Send response data 23 | loop 24 | samba_exporter ->> response.pipe: Wait for response 25 | end 26 | samba_exporter ->> samba_exporter: Process response 27 | ``` 28 | -------------------------------------------------------------------------------- /docs/UserDocs/ServiceIntegration.md: -------------------------------------------------------------------------------- 1 | # Grafana Stack Integration 2 | 3 | Here you can find how to integrate the `samba-exporter` service with the prometheus monitoring stack. 4 | 5 | ## Prometheus 6 | 7 | To add this exporter to your [prometheus database](https://prometheus.io/) you have to add the endpoint as scrape job to the `/etc/prometheus/prometheus.yml` on your prometheus server. Therefor add the lines shown below: 8 | 9 | ```yaml 10 | - job_name: 'Samba exporter node on server.local' 11 | metrics_path: metrics 12 | static_configs: 13 | - targets: ['server.local:9922'] 14 | ``` 15 | 16 | Replace `server.local` with the network name of your samba server. 17 | 18 | **Attention** When prometheus and samba-exporter are running on different instances you need to configure the *samba-exporter service* so it exposes the data on another interface then the loopback device. Therefore change the **-web.listen-address** in `/etc/default/samba_exporter`. 19 | 20 | ## Grafana 21 | 22 | For [grafana](https://grafana.com) an example dashboard is installed with the debian package and can be found at `/usr/share/doc/samba-exporter/grafana/SambaService.json` 23 | 24 | Here is a screenshot of the example dashboard on a live system: 25 | 26 | ![Screenshot of dashboard for the samba service](./../assets/Samba-Dashboard.png) 27 | 28 | When [importing](https://grafana.com/docs/grafana/latest/dashboards/export-import/#import-dashboard) this dashboard you need to change `server.local` to the network name of your samba server. 29 | 30 | Here is a screenshot to import dashboard with this example json file `SambaService.json`, and you need to replace the `prefix` name `server.local` with the network name of your samba server, like `localhost:9922`. 31 | 32 | ![Screenshot from impprting the example dashboard to Grafana](./../assets/import_dashboard_with_json.png) 33 | -------------------------------------------------------------------------------- /docs/UserDocs/UserGuide.md: -------------------------------------------------------------------------------- 1 | # User Guide 2 | 3 | For user documentation please read the man pages: 4 | 5 | - [samba_exporter](https://imker25.github.io/samba_exporter/manpages/samba_exporter.1.html) 6 | - [samba_statusd](https://imker25.github.io/samba_exporter/manpages/samba_statusd.1.html) 7 | - [start_samba_statusd](https://imker25.github.io/samba_exporter/manpages/start_samba_statusd.1.html) 8 | 9 | In case you installed the package already, you can read the man pages using man. For example: 10 | 11 | ```bash 12 | man samba_exporter 13 | ``` 14 | 15 | ## Exported values 16 | 17 | A list of all exported values can be found at the [samba_exporter man page](https://imker25.github.io/samba_exporter/manpages/samba_exporter.1.html). 18 | 19 | ## Problems and solutions 20 | 21 | In case you are running into problems when requesting data from the samba-exporter service. Please first of all stop both required services: 22 | 23 | ```sh 24 | sudo systemctl stop samba_exporter 25 | sudo systemctl stop samba_statusd 26 | ``` 27 | 28 | Delete the pipes used for communication between the services: 29 | 30 | ```sh 31 | sudo rm -f /run/samba_exporter.* 32 | ``` 33 | 34 | Start the services again: 35 | 36 | ```sh 37 | sudo systemctl start samba_statusd 38 | sudo systemctl start samba_exporter 39 | ``` 40 | -------------------------------------------------------------------------------- /docs/assets/Samba-Dashboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imker25/samba_exporter/355ba3fac23a932039d6d0814d50d599fa33b793/docs/assets/Samba-Dashboard.png -------------------------------------------------------------------------------- /docs/assets/import_dashboard_with_json.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imker25/samba_exporter/355ba3fac23a932039d6d0814d50d599fa33b793/docs/assets/import_dashboard_with_json.png -------------------------------------------------------------------------------- /docs/assets/samba-exporter.icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/imker25/samba_exporter/355ba3fac23a932039d6d0814d50d599fa33b793/docs/assets/samba-exporter.icon.png -------------------------------------------------------------------------------- /docs/assets/samba-exporter.icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 15 | 17 | 35 | 38 | 39 | 47 | 54 | 61 | 62 | -------------------------------------------------------------------------------- /install/debian/compat: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /install/debian/conffiles: -------------------------------------------------------------------------------- 1 | /etc/default/samba_exporter 2 | /etc/default/samba_statusd 3 | -------------------------------------------------------------------------------- /install/debian/control: -------------------------------------------------------------------------------- 1 | Source: samba-exporter 2 | Maintainer: Tobias Zellner 3 | Section: utils 4 | Priority: optional 5 | Standards-Version: 4.5.0 6 | Build-Depends: libc6 (>= 2.3.2), 7 | golang-1.16, 8 | gzip, 9 | ronn, 10 | debhelper (>=12.10), 11 | procps, 12 | golang-any, 13 | golang-github-go-kit-kit-dev, 14 | golang-github-prometheus-client-golang-dev, 15 | golang-github-prometheus-common-dev, 16 | golang-gopkg-alecthomas-kingpin.v2-dev, 17 | golang-github-shirou-gopsutil-dev, 18 | dh-golang, 19 | 20 | 21 | Package: samba-exporter 22 | Architecture: amd64 23 | Depends: libc6 (>= 2.3.2), samba, systemd, gzip, procps 24 | Enhances: samba 25 | Description: Prometheus exporter to get metrics of a samba server 26 | This is a prometheus exporter to get metrics of a samba server. 27 | It uses smbstatus to collect the data and converts the result into 28 | prometheus style data. 29 | The prometheus style data can be requested manually on port 9922 30 | using a http client. Or a prometheus database sever can be configured 31 | to collect the data by scraping port 9922 on the samba server. 32 | HomePage: https://imker25.github.io/samba_exporter/ 33 | -------------------------------------------------------------------------------- /install/debian/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: samba-exporter 3 | Source: https://github.com/imker25/samba_exporter 4 | 5 | Files: * 6 | Copyright: 2021 Tobias Zellner 7 | 8 | License: Apache-2.0 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | . 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | . 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | . 21 | On Debian systems, the complete text of the Apache version 2.0 license 22 | can be found in "/usr/share/common-licenses/Apache-2.0". -------------------------------------------------------------------------------- /install/debian/postinst: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | # summary of how this script can be called: 6 | # * `configure' 7 | # * `abort-upgrade' 8 | # * `abort-remove' `in-favour' 9 | # 10 | # * `abort-deconfigure' `in-favour' 11 | # `removing' 12 | # 13 | # for details, see http://www.debian.org/doc/debian-policy/ or 14 | # the debian-policy package 15 | # 16 | # quoting from the policy: 17 | # Any necessary prompting should almost always be confined to the 18 | # post-installation script, and should be protected with a conditional 19 | # so that unnecessary prompting doesn't happen if a package's 20 | # installation fails and the `postinst' is called with `abort-upgrade', 21 | # `abort-remove' or `abort-deconfigure'. 22 | 23 | case "$1" in 24 | configure) 25 | # Unzipp zipped docs 26 | if [ -f "/usr/share/doc/samba-exporter/grafana/SambaService.json.gz" ]; then 27 | gzip -d -f "/usr/share/doc/samba-exporter/grafana/SambaService.json.gz" 28 | fi 29 | if [ -f "/usr/share/doc/samba-exporter/docs/DeveloperDocs/ActionsAndReleases.md.gz" ]; then 30 | gzip -d -f "/usr/share/doc/samba-exporter/docs/DeveloperDocs/ActionsAndReleases.md.gz" 31 | fi 32 | # Add samba-exporter user if needed 33 | if ! getent passwd samba-exporter > /dev/null; then 34 | adduser --quiet --system --no-create-home --home /nonexistent --group --gecos "samba-exporter daemon" samba-exporter || true 35 | fi 36 | # Ensure the daemons are known 37 | systemctl daemon-reload 38 | # Ensure the daemons start automaticaly 39 | systemctl enable samba_statusd.service 40 | systemctl enable samba_exporter.service 41 | # Ensure the daemons run the latest version 42 | systemctl restart samba_statusd.service 43 | systemctl restart samba_exporter.service 44 | ;; 45 | 46 | abort-upgrade|abort-remove|abort-deconfigure) 47 | : 48 | ;; 49 | 50 | *) 51 | echo "postinst called with unknown argument \`$1'" >&2 52 | exit 1 53 | ;; 54 | esac 55 | -------------------------------------------------------------------------------- /install/debian/postrm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | case "$1" in 6 | purge) 7 | # In case the pacakge gets purged, we remove the daemon user 8 | if getent passwd samba-exporter > /dev/null; then 9 | deluser --system samba-exporter 10 | fi 11 | systemctl daemon-reload 12 | if [ -d "/usr/share/doc/samba-exporter" ]; then 13 | rm -rf "/usr/share/doc/samba-exporter" 14 | fi 15 | ;; 16 | remove) 17 | # When the package got removed the service files got deleted. So systemd can now remove the services from its internal db 18 | systemctl daemon-reload 19 | if [ -d "/usr/share/doc/samba-exporter" ]; then 20 | rm -rf "/usr/share/doc/samba-exporter" 21 | fi 22 | ;; 23 | esac -------------------------------------------------------------------------------- /install/debian/prerm: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | request_pipe_file="/run/samba_exporter.request.pipe" 4 | response_pipe_file="/run/samba_exporter.response.pipe" 5 | if [ "$1" = remove ]; then 6 | # Stop the services before removing the package 7 | systemctl stop samba_statusd.service 8 | systemctl stop samba_exporter.service 9 | if [ -p "$request_pipe_file" ]; then 10 | rm "$request_pipe_file" 11 | fi 12 | if [ -p "$response_pipe_file" ]; then 13 | rm "$response_pipe_file" 14 | fi 15 | fi -------------------------------------------------------------------------------- /install/debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | 3 | include /usr/share/dpkg/pkg-info.mk 4 | 5 | ROOT = $(CURDIR)/debian/samba-exporter 6 | SHORT_VERSION = $(file < ${CURDIR}/VersionMaster.txt) 7 | GOCACHE := $(CURDIR)/../.go-build 8 | DH_GOLANG_BUILDPKG := tobi.backfrak.de/cmd/samba_exporter tobi.backfrak.de/cmd/samba_statusd tobi.backfrak.de/internal/commonbl tobi.backfrak.de/internal/smbexporterbl/smbstatusreader tobi.backfrak.de/internal/smbexporterbl/pipecomunication tobi.backfrak.de/internal/smbexporterbl/statisticsGenerator tobi.backfrak.de/internal/smbexporterbl/smbexporter tobi.backfrak.de/internal/smbstatusdbl 9 | export DH_GOLANG_BUILDPKG 10 | export GOCACHE 11 | 12 | BUILDFLAGS = -ldflags="-X main.version=$(SHORT_VERSION)" 13 | export BUILDFLAGS 14 | 15 | override_dh_auto_clean: 16 | rm -rf $(GOCACHE)/* 17 | rm -rf $(CURDIR)/bin/* 18 | rm -rf $(CURDIR)/logs/* 19 | rm -rf $(CURDIR)/tmp/* 20 | mv $(CURDIR)/debian/samba-exporter.manpages $(CURDIR)/debian/bak.samba-exporter.manpages 21 | rm -rf $(ROOT)* 22 | mv $(CURDIR)/debian/bak.samba-exporter.manpages $(CURDIR)/debian/samba-exporter.manpages 23 | 24 | 25 | execute_before_dh_auto_build: 26 | mkdir -p $(GOCACHE) 27 | mv $(CURDIR)/bin/src/src/* $(CURDIR)/bin/src/ 28 | 29 | execute_after_dh_auto_build: 30 | $(CURDIR)/build/CreateManPage.sh 31 | 32 | override_dh_auto_build: 33 | dh_auto_build -- $(BUILDFLAGS) 34 | 35 | override_dh_auto_install: 36 | rm -f $(CURDIR)/debian/conffiles 37 | build/InstallProgram.sh ${CURDIR} ${CURDIR}/bin/bin/ ${ROOT} 38 | echo "Install man pages" 39 | cp $(CURDIR)/src/man/samba_exporter.1 $(CURDIR)/debian/ 40 | cp $(CURDIR)/src/man/samba_statusd.1 $(CURDIR)/debian/ 41 | cp $(CURDIR)/src/man/start_samba_statusd.1 $(CURDIR)/debian/ 42 | 43 | 44 | override_dh_auto_test: 45 | dh_auto_test --no-parallel 46 | 47 | %: 48 | dh $@ --buildsystem=golang --with=golang --builddirectory=$(CURDIR)/bin/ 49 | 50 | -------------------------------------------------------------------------------- /install/debian/samba-exporter.manpages: -------------------------------------------------------------------------------- 1 | debian/samba_statusd.1 2 | debian/start_samba_statusd.1 3 | debian/samba_exporter.1 4 | -------------------------------------------------------------------------------- /install/etc/default/samba_exporter: -------------------------------------------------------------------------------- 1 | # Set the command-line arguments to pass to the samba_exporter daemon 2 | 3 | # Default settings: 4 | # - only listen on local host 5 | # - export all metrics 6 | ARGS='-web.listen-address=127.0.0.1:9922' 7 | 8 | # The prometheus exporter endpoint listen on all network interfaces and exports all metrics 9 | # ARGS='' 10 | 11 | # The prometheus exporter endpoint only listen on 192.168.0.1 and gives verbose log output 12 | # ARGS='-web.listen-address=192.168.0.1:9922 -verbose' 13 | 14 | # The prometheus exporter endpoint only listen on 192.168.0.1 and does not export data about encryption details 15 | # ARGS='-web.listen-address=192.168.0.1:9922 -not-expose-encryption-data' 16 | 17 | # The samba_exporter running with verbose output and output is written into a log file 18 | # ARGS='-verbose -log-file-path=/var/log/samba_exporter.log' 19 | 20 | # Usage of samba_exporter 21 | # -help 22 | # Print this help message 23 | # -log-file-path string 24 | # Give the full file path for a log file. When parameter is not set (as by default), logs will be written to stdout and stderr (default " ") 25 | # -not-expose-client-data 26 | # Set to 'true', no details about the connected clients will be exported 27 | # -not-expose-encryption-data 28 | # Set to 'true', no details about the used encryption or signing will be exported 29 | # -not-expose-pid-data 30 | # Set to 'true', no process IDs will be exported 31 | # -not-expose-share-details 32 | # Set to 'true', no details about the shares will be exported 33 | # -not-expose-user-data 34 | # Set to 'true', no details about the connected users will be exported 35 | # -print-version 36 | # With this flag the program will only print it's version and exit 37 | # -request-timeout int 38 | # The timeout for a request to samba_statusd in seconds (default 5) 39 | # -test-mode 40 | # Run the program in test mode. In this mode the program will always return the same test data. 41 | # To work with samba_statusd both programs needs to run in test mode or not. 42 | # -test-pipe 43 | # Requests status from samba_statusd and exits. May be combined with -test-mode. 44 | # -verbose 45 | # With this flag the program will print verbose output 46 | # -web.listen-address string 47 | # Address to listen on for web interface and telemetry. (default ":9922") 48 | # -web.telemetry-path string 49 | # Path under which to expose metrics. (default "/metrics") -------------------------------------------------------------------------------- /install/etc/default/samba_statusd: -------------------------------------------------------------------------------- 1 | # Set the command-line arguments to pass to the samba_statusd daemon 2 | 3 | # The samba_statusd running without args by default 4 | ARGS='' 5 | 6 | # The samba_statusd running with verbose output 7 | # ARGS='-verbose' 8 | 9 | # The samba_statusd running with verbose output and output is written into a log file 10 | # ARGS='-verbose -log-file-path=/var/log/samba_statusd.log' 11 | 12 | # Usage of samba_statusd 13 | # -help 14 | # Print this help message 15 | # -log-file-path string 16 | # Give the full file path for a log file. When parameter is not set (as by default), logs will be written to stdout and stderr (default " ") 17 | # -print-version 18 | # With this flag the program will only print it's version and exit 19 | # -test-mode 20 | # Run the program in test mode. In this mode the program will always return the same test data. 21 | # To work with samba_exporter both programs needs to run in test mode or not. 22 | # -verbose 23 | # With this flag the program will print verbose output -------------------------------------------------------------------------------- /install/fedora/samba-exporter.from_gradle.spec: -------------------------------------------------------------------------------- 1 | # Spec file to create a samba_exporter RPM binary package out of the ./build.sh (former gradle) build output 2 | 3 | Name: samba-exporter 4 | Version: x.x.x 5 | Release: 1 6 | Summary: Prometheus exporter to get metrics of a samba server 7 | License: ASL 2.0 8 | URL: https://github.com/imker25/samba_exporter 9 | Distribution: Fedora 10 | Group: utils 11 | Requires: samba, systemd, filesystem, binutils, man-db, procps-ng 12 | 13 | %define _rpmdir ../ 14 | %define _rpmfilename %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm 15 | %define _unpackaged_files_terminate_build 0 16 | 17 | 18 | %pre 19 | if [ $1 == 2 ];then 20 | # Stop services before install in case of package upgrade 21 | systemctl stop samba_exporter.service 22 | systemctl stop samba_statusd.service 23 | fi 24 | 25 | 26 | %post 27 | # Add samba-exporter user if needed 28 | if ! getent group samba-exporter > /dev/null ; then 29 | groupadd -r samba-exporter 30 | fi 31 | if ! getent passwd samba-exporter > /dev/null ; then 32 | adduser --system --no-create-home --home-dir /nonexistent --gid samba-exporter --shell /bin/false --comment "samba-exporter daemon" samba-exporter || true 33 | fi 34 | # Ensure the daemons are known 35 | systemctl daemon-reload 36 | if [ $1 == 1 ];then 37 | # Ensure the daemons start automaticaly in case of package installation 38 | systemctl enable samba_statusd.service 39 | systemctl enable samba_exporter.service 40 | fi 41 | # Ensure the daemons run the latest version 42 | systemctl start samba_statusd.service 43 | systemctl start samba_exporter.service 44 | # Ensure man-db is updated 45 | mandb > /dev/null 46 | 47 | 48 | %preun 49 | if [ $1 == 0 ];then 50 | request_pipe_file="/run/samba_exporter.request.pipe" 51 | response_pipe_file="/run/samba_exporter.response.pipe" 52 | # Stop the services before removing the package 53 | systemctl stop samba_statusd.service 54 | systemctl stop samba_exporter.service 55 | if [ -p "$request_pipe_file" ]; then 56 | rm "$request_pipe_file" 57 | fi 58 | if [ -p "$response_pipe_file" ]; then 59 | rm "$response_pipe_file" 60 | fi 61 | fi 62 | 63 | %postun 64 | if [ $1 == 0 ];then 65 | # When the package got removed the service files got deleted. So systemd can now remove the services from its internal db 66 | systemctl daemon-reload 67 | if [ -d "/usr/share/doc/samba-exporter" ]; then 68 | rm -rf "/usr/share/doc/samba-exporter" 69 | fi 70 | fi 71 | 72 | %description 73 | This is a prometheus exporter to get metrics of a samba server. 74 | It uses smbstatus to collect the data and converts the result into 75 | prometheus style data. 76 | The prometheus style data can be requested manually on port 9922 77 | using a http client. Or a prometheus database sever can be configured 78 | to collect the data by scraping port 9922 on the samba server. 79 | 80 | %install 81 | rm -rf %{buildroot} 82 | mv -v %{_topdir}/PREBINROOT/ %{buildroot} 83 | 84 | 85 | %files 86 | %config(noreplace) "/etc/default/samba_exporter" 87 | %config(noreplace) "/etc/default/samba_statusd" 88 | "/lib/systemd/system/samba_exporter.service" 89 | "/lib/systemd/system/samba_statusd.service" 90 | "/usr/bin/samba_exporter" 91 | "/usr/bin/samba_statusd" 92 | "/usr/bin/start_samba_statusd" 93 | %dir "/usr/share/" 94 | %docdir "/usr/share/doc/" 95 | %docdir "/usr/share/doc/samba-exporter/" 96 | %doc "/usr/share/doc/samba-exporter/README.md" 97 | %license "/usr/share/doc/samba-exporter/LICENSE" 98 | %docdir "/usr/share/doc/samba-exporter/docs/" 99 | %docdir "/usr/share/doc/samba-exporter/docs/DeveloperDocs/" 100 | %doc "/usr/share/doc/samba-exporter/docs/DeveloperDocs/ActionsAndReleases.md" 101 | %doc "/usr/share/doc/samba-exporter/docs/DeveloperDocs/Compile.md" 102 | %doc "/usr/share/doc/samba-exporter/docs/DeveloperDocs/Hints.md" 103 | %doc "/usr/share/doc/samba-exporter/docs/Index.md" 104 | %docdir "/usr/share/doc/samba-exporter/docs/Installation/" 105 | %doc "/usr/share/doc/samba-exporter/docs/Installation/InstallationGuide.md" 106 | %doc "/usr/share/doc/samba-exporter/docs/Installation/SupportedVersions.md" 107 | %docdir "/usr/share/doc/samba-exporter/docs/UserDocs/" 108 | %doc "/usr/share/doc/samba-exporter/docs/UserDocs/Concept.md" 109 | %doc "/usr/share/doc/samba-exporter/docs/UserDocs/ServiceIntegration.md" 110 | %doc "/usr/share/doc/samba-exporter/docs/UserDocs/UserGuide.md" 111 | %docdir "/usr/share/doc/samba-exporter/docs/assets/" 112 | %doc "/usr/share/doc/samba-exporter/docs/assets/Samba-Dashboard.png" 113 | %doc "/usr/share/doc/samba-exporter/docs/assets/samba-exporter.icon.png" 114 | %docdir "/usr/share/doc/samba-exporter/grafana/" 115 | %doc "/usr/share/doc/samba-exporter/grafana/SambaService.json" 116 | %doc "/usr/share/man/man1/samba_exporter.1.gz" 117 | %doc "/usr/share/man/man1/samba_statusd.1.gz" 118 | %doc "/usr/share/man/man1/start_samba_statusd.1.gz" 119 | -------------------------------------------------------------------------------- /install/lib/systemd/system/samba_exporter.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=Prometheus samba-exporter service, based on https://github.com/imker25/samba_exporter 3 | Requires=samba_statusd.service 4 | After=network-online.target samba_statusd.service 5 | 6 | [Service] 7 | Type=exec 8 | Environment="LANG=C" 9 | Environment="LC_TIME=c.utf-8" 10 | Environment="LC_NUMERIC=c.UTF-8" 11 | EnvironmentFile=/etc/default/samba_exporter 12 | ExecStart=/usr/bin/samba_exporter $ARGS 13 | ExecReload=/bin/kill -HUP $MAINPID 14 | Restart=on-failure 15 | KillSignal=SIGTERM 16 | User=samba-exporter 17 | 18 | [Install] 19 | WantedBy=multi-user.target -------------------------------------------------------------------------------- /install/lib/systemd/system/samba_statusd.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=samba-statusd service for prometheus samba-exporter, based on https://github.com/imker25/samba_exporter 3 | Requires=network-online.target 4 | After=network-online.target 5 | 6 | [Service] 7 | Environment="LANG=C" 8 | Environment="LC_TIME=c.utf-8" 9 | Environment="LC_NUMERIC=c.UTF-8" 10 | Type=forking 11 | EnvironmentFile=/etc/default/samba_statusd 12 | ExecStart=/usr/bin/start_samba_statusd $ARGS 13 | ExecReload=/bin/kill -TERM $MAINPID && /usr/bin/start_samba_statusd $ARGS 14 | Restart=on-failure 15 | ExecStop=/bin/kill -TERM $MAINPID 16 | KillSignal=SIGTERM 17 | User=root 18 | 19 | [Install] 20 | WantedBy=multi-user.target -------------------------------------------------------------------------------- /install/usr/bin/start_samba_statusd: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # ######################################################################################### 3 | # Copyright 2021 by tobi@backfrak.de. All 4 | # rights reserved. Use of this source code is governed 5 | # by a BSD-style license that can be found in the 6 | # LICENSE file. 7 | # ######################################################################################### 8 | 9 | # ######################################################################################### 10 | # Script to start the samba_statusd in productive environemnts 11 | # 12 | # - Will ensure that the pipes for comunication between samba_statusd and samba_exporter 13 | # are correctly setup and then start samba_statusd with any given paramter 14 | # ######################################################################################### 15 | # echo "Startup samba_statusd with ARGS: $*" 16 | pipe_permissions="660" 17 | pipe_owner="root:samba-exporter" 18 | request_pipe_file="/run/samba_exporter.request.pipe" 19 | response_pipe_file="/run/samba_exporter.response.pipe" 20 | samba_statusd="/usr/bin/samba_statusd" 21 | 22 | # Check that samba_statusd is installed as expected 23 | if [ ! -f "$samba_statusd" ]; then 24 | echo "Error: $samba_statusd not found" 25 | exit 1 26 | fi 27 | 28 | # Setup request pipe 29 | if [ -p "$request_pipe_file" ]; then 30 | rm "$request_pipe_file" 31 | fi 32 | mkfifo "$request_pipe_file" 33 | chown "$pipe_owner" "$request_pipe_file" 34 | chmod "$pipe_permissions" "$request_pipe_file" 35 | 36 | # Setup response pipe 37 | if [ -p "$response_pipe_file" ]; then 38 | rm "$response_pipe_file" 39 | fi 40 | mkfifo "$response_pipe_file" 41 | chown "$pipe_owner" "$response_pipe_file" 42 | chmod "$pipe_permissions" "$response_pipe_file" 43 | 44 | # Run samba_statusd with the given arguments as daemon 45 | # echo "Starting as daemon: $samba_statusd $*" 46 | $samba_statusd $* & 47 | 48 | # Ensure deamon is up 49 | sleep 0.05 50 | 51 | # Exit the startup script 52 | exit 0 -------------------------------------------------------------------------------- /src/man/samba_statusd.1.ronn: -------------------------------------------------------------------------------- 1 | samba_statusd(1) -- part of the samba-exporter package 2 | ============================================= 3 | 4 | ## SYNOPSIS 5 | 6 | `samba_statusd` [options] 7 | 8 | ## DESCRIPTION 9 | 10 | **samba_statusd** The `smbstatus` part samba-exporter package (see `man samba_exporter` for details).
11 | 12 | The tool is usually stated as daemon by systemd as `samba_statusd.service` using the `start_samba_statusd` script.
13 | 14 | It communicates with the `samba_exporter.service` using the named pipes `/run/samba_exporter.request.pipe` and `/run/samba_exporter.response.pipe`. 15 | 16 | ## OPTIONS 17 | 18 | You might want to use one of the following optional parameters. 19 | 20 | * `-help`: 21 | Print the programs help message and exit 22 | 23 | * `-log-file-path string`: 24 | Give the full file path for a log file. When parameter is not set (as by default), logs will be written to stdout and stderr (default " ") 25 | 26 | * `-print-version`: 27 | With this flag the program will only print it's version and exit 28 | 29 | * `-test-mode`: 30 | Run the program in test mode.
31 | In this mode the program will always return the same test data. To work with samba_exporter both programs needs to run in test mode or not. 32 | 33 | * `-verbose`: 34 | With this flag the program will print verbose output 35 | 36 | To change the behavior of the samba_statusd service update the `/etc/default/samba_statusd` according to your needs. 37 | You can add any option shown in the help output of `samba_statusd` to the `ARGS` variable.
38 | 39 | You may not want to start the service with arguments that will exit before listening starts like `-help` or `-print-version`. 40 | 41 | 42 | ## EXAMPLES 43 | 44 | To stop, start or restart the service use `systemctl`, e. g.:
45 | `sudo systemctl stop samba_statusd` 46 | 47 | To read the log output use `journalctl`, e. g.
48 | `sudo journalctl -u samba_statusd` 49 | 50 | **Remark:** Due to the services dependencies `samba_exporter` service stops whenever `samba_statusd` stops. 51 | And `samba_statusd` always starts when `samba_exporter` is started if not already running. 52 | 53 | ## Files 54 | 55 | * `/etc/default/samba_statusd` The configuration file for the samba_exporter service 56 | * `/run/samba_exporter.request.pipe` The pipe samba_exporter requests the status from samba_statusd 57 | * `/run/samba_exporter.response.pipe` The pipe samba_statusd answers requests from samba_exporter 58 | 59 | ## BUGS 60 | 61 | See
62 | In case you found a new bug please also report as github issue on the projects page. 63 | 64 | ## COPYRIGHT 65 | 66 | samba_statusd is Copyright (C) 2021 Tobias Zellner 67 | 68 | ## SEE ALSO 69 | 70 | samba_exporter(1), start_samba_statusd(1) -------------------------------------------------------------------------------- /src/man/start_samba_statusd.1.ronn: -------------------------------------------------------------------------------- 1 | start_samba_statusd(1) -- part of the samba-exporter package 2 | ============================================= 3 | 4 | ## SYNOPSIS 5 | 6 | `start_samba_statusd` [options] 7 | 8 | ## DESCRIPTION 9 | 10 | **start_samba_statusd** Script used by systemd to start the samba_statusd as service
11 | 12 | The script ensures that the named pipes `/run/samba_exporter.request.pipe` and `/run/samba_exporter.response.pipe` 13 | exists in the right state when the samba_statusd service starts. 14 | 15 | ## OPTIONS 16 | 17 | As a startup script it passthrough all arguments to `samba_statusd`. So please see `man samba_statusd` for more information. 18 | 19 | ## BUGS 20 | 21 | See
22 | In case you found a new bug please also report as github issue on the projects page. 23 | 24 | ## COPYRIGHT 25 | 26 | start_samba_statusd is Copyright (C) 2021 Tobias Zellner 27 | 28 | ## SEE ALSO 29 | 30 | samba_exporter(1), samba_statusd(1) -------------------------------------------------------------------------------- /src/page/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Samba Exporter 6 | 7 | 8 | 9 | 10 | 11 |
12 | Please open the 13 | documentaion page 14 | in case you not forwared. 15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/cmd/samba_exporter/go.mod: -------------------------------------------------------------------------------- 1 | module tobi.backfrak.de/cmd/samba_exporter 2 | 3 | go 1.23 4 | 5 | require tobi.backfrak.de/internal/commonbl v0.0.0 6 | 7 | replace tobi.backfrak.de/internal/commonbl v0.0.0 => ../../internal/commonbl 8 | 9 | require tobi.backfrak.de/internal/testhelper v0.0.0 10 | 11 | replace tobi.backfrak.de/internal/testhelper v0.0.0 => ../../internal/testhelper 12 | 13 | require tobi.backfrak.de/internal/smbexporterbl/pipecomunication v0.0.0 14 | 15 | replace tobi.backfrak.de/internal/smbexporterbl/pipecomunication v0.0.0 => ../../internal/smbexporterbl/pipecomunication 16 | 17 | require tobi.backfrak.de/internal/smbexporterbl/statisticsGenerator v0.0.0 18 | 19 | replace tobi.backfrak.de/internal/smbexporterbl/statisticsGenerator v0.0.0 => ../../internal/smbexporterbl/statisticsGenerator 20 | 21 | require tobi.backfrak.de/internal/smbexporterbl/smbstatusreader v0.0.0 22 | 23 | replace tobi.backfrak.de/internal/smbexporterbl/smbstatusreader v0.0.0 => ../../internal/smbexporterbl/smbstatusreader 24 | 25 | require tobi.backfrak.de/internal/smbexporterbl/smbexporter v0.0.0 26 | 27 | replace tobi.backfrak.de/internal/smbexporterbl/smbexporter v0.0.0 => ../../internal/smbexporterbl/smbexporter 28 | 29 | replace tobi.backfrak.de/internal/smbstatusout v0.0.0 => ../../internal/smbstatusout 30 | 31 | require github.com/prometheus/client_golang v1.19.0 32 | 33 | require ( 34 | github.com/beorn7/perks v1.0.1 // indirect 35 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 36 | github.com/prometheus/client_model v0.5.0 // indirect 37 | github.com/prometheus/common v0.48.0 // indirect 38 | github.com/prometheus/procfs v0.12.0 // indirect 39 | golang.org/x/sys v0.16.0 // indirect 40 | google.golang.org/protobuf v1.33.0 // indirect 41 | ) 42 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/cmd/samba_exporter/go.sum: -------------------------------------------------------------------------------- 1 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 2 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 3 | github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= 4 | github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 5 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 6 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 7 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 8 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 9 | github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU= 10 | github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= 11 | github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= 12 | github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= 13 | github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE= 14 | github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= 15 | github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= 16 | github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= 17 | golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= 18 | golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 19 | google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= 20 | google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= 21 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/cmd/samba_exporter/main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "fmt" 10 | "strings" 11 | "sync" 12 | "testing" 13 | 14 | "tobi.backfrak.de/internal/commonbl" 15 | "tobi.backfrak.de/internal/smbexporterbl/pipecomunication" 16 | "tobi.backfrak.de/internal/smbexporterbl/smbstatusreader" 17 | "tobi.backfrak.de/internal/testhelper" 18 | ) 19 | 20 | var mMutext sync.Mutex = sync.Mutex{} 21 | 22 | func TestGetVersion(t *testing.T) { 23 | version := getVersion() 24 | 25 | if !strings.Contains(version, "Version:") { 26 | t.Errorf("The version string has not the expected format") 27 | } 28 | 29 | printVersion() 30 | } 31 | 32 | func TestTestPipeMode(t *testing.T) { 33 | mMutext.Lock() 34 | defer mMutext.Unlock() 35 | 36 | oldParmas := params 37 | defer func() { params = oldParmas }() 38 | 39 | params.RequestTimeOut = 1 40 | requestHandler := commonbl.NewPipeHandler(true, commonbl.RequestPipe) 41 | responseHandler := commonbl.NewPipeHandler(true, commonbl.ResposePipe) 42 | testLogger := testhelper.NewTestLogger(true) 43 | logger = testLogger 44 | 45 | err := testPipeMode(requestHandler, responseHandler) 46 | if err == nil { 47 | t.Errorf("Got no error, but expected one") 48 | } 49 | 50 | switch err.(type) { 51 | case *pipecomunication.SmbStatusTimeOutError: 52 | fmt.Println("OK") 53 | default: 54 | t.Errorf("Got error of type '%s', but expected type '*pipecomunication.SmbStatusTimeOutError'", err) 55 | } 56 | 57 | if testLogger.GetOutputCount() != 4 { 58 | t.Errorf("Got '%d' output messages but expected '4'", testLogger.GetOutputCount()) 59 | } 60 | } 61 | 62 | func TestHandleTestResponse(t *testing.T) { 63 | mMutext.Lock() 64 | defer mMutext.Unlock() 65 | 66 | oldParmas := params 67 | defer func() { params = oldParmas }() 68 | 69 | testLogger := testhelper.NewTestLogger(true) 70 | logger = testLogger 71 | shares := smbstatusreader.GetShareData(commonbl.TestShareResponse, logger) 72 | processes := smbstatusreader.GetProcessData(commonbl.TestProcessResponse, logger) 73 | locks := smbstatusreader.GetLockData(commonbl.TestLockResponse, logger) 74 | psData := smbstatusreader.GetPsData(commonbl.TestPsResponse(), logger) 75 | 76 | handleTestResponse(processes, shares, locks, psData) 77 | 78 | if testLogger.GetOutputCount() != 1 { 79 | t.Errorf("Got '%d' output messages but expected '1'", testLogger.GetOutputCount()) 80 | } 81 | } 82 | 83 | func TestMainWithHelp(t *testing.T) { 84 | mMutext.Lock() 85 | defer mMutext.Unlock() 86 | 87 | oldParmas := params 88 | defer func() { params = oldParmas }() 89 | 90 | params.Test = true 91 | params.Help = true 92 | 93 | res := realMain() 94 | if res != 0 { 95 | t.Errorf("Got %d from main, but expected 0", res) 96 | } 97 | 98 | } 99 | 100 | func TestMainWithVerbose(t *testing.T) { 101 | mMutext.Lock() 102 | defer mMutext.Unlock() 103 | 104 | oldParmas := params 105 | defer func() { params = oldParmas }() 106 | 107 | params.Test = true 108 | params.Help = true 109 | params.Verbose = true 110 | 111 | res := realMain() 112 | if res != 0 { 113 | t.Errorf("Got %d from main, but expected 0", res) 114 | } 115 | 116 | } 117 | 118 | func TestMainWithPrintVersion(t *testing.T) { 119 | mMutext.Lock() 120 | defer mMutext.Unlock() 121 | 122 | oldParmas := params 123 | defer func() { params = oldParmas }() 124 | 125 | params.Test = true 126 | params.PrintVersion = true 127 | 128 | res := realMain() 129 | if res != 0 { 130 | t.Errorf("Got %d from main, but expected 0", res) 131 | } 132 | 133 | } 134 | 135 | func TestMainWithTestPipeMode(t *testing.T) { 136 | mMutext.Lock() 137 | defer mMutext.Unlock() 138 | 139 | oldParmas := params 140 | defer func() { params = oldParmas }() 141 | 142 | params.Test = true 143 | params.TestPipeMode = true 144 | 145 | res := realMain() 146 | if res != -2 { 147 | t.Errorf("Got %d from main, but expected -2", res) 148 | } 149 | 150 | } 151 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/cmd/samba_exporter/parameters_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "testing" 10 | ) 11 | 12 | func TestHandleComandlineOptions(t *testing.T) { 13 | mMutext.Lock() 14 | defer mMutext.Unlock() 15 | 16 | handleComandlineOptions() 17 | if params.PrintVersion { 18 | t.Errorf("params.PrintVersion is true, but should not") 19 | } 20 | 21 | if params.Verbose { 22 | t.Errorf("params.Verbose is true, but should not") 23 | } 24 | } 25 | 26 | func TestCustomHelpMessage(t *testing.T) { 27 | mMutext.Lock() 28 | defer mMutext.Unlock() 29 | 30 | customHelpMessage() 31 | } 32 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/cmd/samba_exporter/paramters.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "flag" 10 | "fmt" 11 | "os" 12 | 13 | "tobi.backfrak.de/internal/commonbl" 14 | "tobi.backfrak.de/internal/smbexporterbl/statisticsGenerator" 15 | ) 16 | 17 | // The paramters for this executable 18 | type parmeters struct { 19 | commonbl.Parmeters 20 | statisticsGenerator.StatisticsGeneratorSettings 21 | TestPipeMode bool 22 | ListenAddress string 23 | MetricsPath string 24 | RequestTimeOut int 25 | } 26 | 27 | var params parmeters 28 | 29 | // Setup commandline parameters and parse them 30 | func handleComandlineOptions() { 31 | 32 | // Setup the usabel parametes 33 | flag.BoolVar(¶ms.PrintVersion, "print-version", false, "With this flag the program will only print it's version and exit") 34 | flag.BoolVar(¶ms.Verbose, "verbose", false, "With this flag the program will print verbose output") 35 | flag.BoolVar(¶ms.Test, "test-mode", false, 36 | "Run the program in test mode. In this mode the program will always return the same test data. To work with samba_statusd both programs needs to run in test mode or not.") 37 | flag.BoolVar(¶ms.Help, "help", false, "Print this help message") 38 | flag.BoolVar(¶ms.TestPipeMode, "test-pipe", false, "Requests status from samba_statusd and exits. May be combined with -test-mode.") 39 | flag.StringVar(¶ms.ListenAddress, "web.listen-address", ":9922", "Address to listen on for web interface and telemetry.") 40 | flag.StringVar(¶ms.MetricsPath, "web.telemetry-path", "/metrics", "Path under which to expose metrics.") 41 | flag.IntVar(¶ms.RequestTimeOut, "request-timeout", 5, "The timeout for a request to samba_statusd in seconds") 42 | flag.BoolVar(¶ms.DoNotExportEncryption, "not-expose-encryption-data", false, "Set to 'true', no details about the used encryption or signing will be exported") 43 | flag.BoolVar(¶ms.DoNotExportClient, "not-expose-client-data", false, "Set to 'true', no details about the connected clients will be exported") 44 | flag.BoolVar(¶ms.DoNotExportUser, "not-expose-user-data", false, "Set to 'true', no details about the connected users will be exported") 45 | flag.BoolVar(¶ms.DoNotExportPid, "not-expose-pid-data", false, "Set to 'true', no process IDs will be exported") 46 | flag.BoolVar(¶ms.DoNotExportShareDetails, "not-expose-share-details", false, "Set to 'true', no details about the shares will be exported") 47 | flag.StringVar(¶ms.LogFilePath, "log-file-path", " ", 48 | "Give the full file path for a log file. When parameter is not set (as by default), logs will be written to stdout and stderr") 49 | 50 | // Overwrite the std Usage function with some custom stuff 51 | flag.Usage = customHelpMessage 52 | 53 | // Read the given flags 54 | flag.Parse() 55 | } 56 | 57 | // customHelpMessage - Print he customized help message 58 | func customHelpMessage() { 59 | fmt.Fprintln(os.Stdout, fmt.Sprintf("%s: prometheus exporter for the samba file server. Collects data using the samba_statusd service.", os.Args[0])) 60 | fmt.Fprintln(os.Stdout, fmt.Sprintf("Program %s", getVersion())) 61 | fmt.Fprintln(os.Stdout) 62 | fmt.Fprintln(os.Stdout, fmt.Sprintf("Usage: %s [options]", os.Args[0])) 63 | fmt.Fprintln(os.Stdout, "Options:") 64 | flag.PrintDefaults() 65 | fmt.Fprintln(os.Stdout) 66 | fmt.Fprintln(os.Stdout, "This program is used to run as a service. To change the service behavior edit '/etc/default/samba_exporter' according to your needs.") 67 | } 68 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/cmd/samba_statusd/go.mod: -------------------------------------------------------------------------------- 1 | module tobi.backfrak.de/cmd/samba_statusd 2 | 3 | go 1.23 4 | 5 | require tobi.backfrak.de/internal/commonbl v0.0.0 6 | 7 | replace tobi.backfrak.de/internal/commonbl v0.0.0 => ../../internal/commonbl 8 | 9 | require tobi.backfrak.de/internal/testhelper v0.0.0 10 | 11 | replace tobi.backfrak.de/internal/testhelper v0.0.0 => ../../internal/testhelper 12 | 13 | require tobi.backfrak.de/internal/smbstatusdbl v0.0.0 14 | 15 | replace tobi.backfrak.de/internal/smbstatusdbl v0.0.0 => ../../internal/smbstatusdbl 16 | 17 | require ( 18 | github.com/go-ole/go-ole v1.2.6 // indirect 19 | github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect 20 | github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect 21 | github.com/shirou/gopsutil/v3 v3.23.2 // indirect 22 | github.com/tklauser/go-sysconf v0.3.11 // indirect 23 | github.com/tklauser/numcpus v0.6.0 // indirect 24 | github.com/yusufpapurcu/wmi v1.2.2 // indirect 25 | golang.org/x/sys v0.5.0 // indirect 26 | ) 27 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/cmd/samba_statusd/go.mod.gopsutil-v2: -------------------------------------------------------------------------------- 1 | module tobi.backfrak.de/cmd/samba_statusd 2 | 3 | 4 | 5 | require tobi.backfrak.de/internal/commonbl v0.0.0 6 | replace tobi.backfrak.de/internal/commonbl v0.0.0 => ../../internal/commonbl 7 | 8 | require tobi.backfrak.de/internal/smbstatusdbl v0.0.0 9 | replace tobi.backfrak.de/internal/smbstatusdbl v0.0.0 => ../../internal/smbstatusdbl 10 | 11 | require tobi.backfrak.de/internal/testhelper v0.0.0 12 | replace tobi.backfrak.de/internal/testhelper v0.0.0 => ../../internal/testhelper 13 | 14 | require ( 15 | github.com/go-ole/go-ole v1.2.6 // indirect 16 | github.com/shirou/gopsutil v3.21.11+incompatible // indirect 17 | github.com/tklauser/go-sysconf v0.3.10 // indirect 18 | github.com/tklauser/numcpus v0.4.0 // indirect 19 | github.com/yusufpapurcu/wmi v1.2.2 // indirect 20 | golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect 21 | ) 22 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/cmd/samba_statusd/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 2 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 3 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 4 | github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= 5 | github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= 6 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 7 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 8 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 9 | github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= 10 | github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= 11 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 12 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 13 | github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= 14 | github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= 15 | github.com/shirou/gopsutil/v3 v3.23.2 h1:PAWSuiAszn7IhPMBtXsbSCafej7PqUOvY6YywlQUExU= 16 | github.com/shirou/gopsutil/v3 v3.23.2/go.mod h1:gv0aQw33GLo3pG8SiWKiQrbDzbRY1K80RyZJ7V4Th1M= 17 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 18 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 19 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 20 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 21 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 22 | github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= 23 | github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= 24 | github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= 25 | github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= 26 | github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= 27 | github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= 28 | github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= 29 | github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= 30 | golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 31 | golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 32 | golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 33 | golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= 34 | golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 35 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 36 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 37 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 38 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 39 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 40 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/cmd/samba_statusd/go.sum.gopsutil-v2: -------------------------------------------------------------------------------- 1 | github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= 2 | github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= 3 | github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= 4 | github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= 5 | github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw= 6 | github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= 7 | github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o= 8 | github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= 9 | github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= 10 | github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= 11 | golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 12 | golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 13 | golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI= 14 | golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 15 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/cmd/samba_statusd/parameters_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "testing" 10 | ) 11 | 12 | func TestHandleComandlineOptions(t *testing.T) { 13 | mMutext.Lock() 14 | defer mMutext.Unlock() 15 | 16 | handleComandlineOptions() 17 | if params.PrintVersion { 18 | t.Errorf("params.PrintVersion is true, but should not") 19 | } 20 | 21 | if params.Verbose { 22 | t.Errorf("params.Verbose is true, but should not") 23 | } 24 | } 25 | 26 | func TestCustomHelpMessage(t *testing.T) { 27 | customHelpMessage() 28 | } 29 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/cmd/samba_statusd/paramters.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "flag" 10 | "fmt" 11 | "os" 12 | 13 | "tobi.backfrak.de/internal/commonbl" 14 | ) 15 | 16 | // The paramters for this executable 17 | type parmeters struct { 18 | commonbl.Parmeters 19 | } 20 | 21 | var params parmeters 22 | 23 | // Setup commandline parameters and parse them 24 | func handleComandlineOptions() { 25 | 26 | // Setup the usabel parametes 27 | flag.BoolVar(¶ms.PrintVersion, "print-version", false, "With this flag the program will only print it's version and exit") 28 | flag.BoolVar(¶ms.Verbose, "verbose", false, "With this flag the program will print verbose output") 29 | flag.BoolVar(¶ms.Test, "test-mode", false, 30 | "Run the program in test mode. In this mode the program will always return the same test data. To work with samba_exporter both programs needs to run in test mode or not.") 31 | flag.BoolVar(¶ms.Help, "help", false, "Print this help message") 32 | flag.StringVar(¶ms.LogFilePath, "log-file-path", " ", 33 | "Give the full file path for a log file. When parameter is not set (as by default), logs will be written to stdout and stderr") 34 | 35 | // Overwrite the std Usage function with some custom stuff 36 | flag.Usage = customHelpMessage 37 | 38 | // Read the given flags 39 | flag.Parse() 40 | } 41 | 42 | // customHelpMessage - Print he customized help message 43 | func customHelpMessage() { 44 | fmt.Fprintln(os.Stdout, fmt.Sprintf("%s: Wrapper for smbstatus. Collects data used by the samba_exporter service.", os.Args[0])) 45 | fmt.Fprintln(os.Stdout, fmt.Sprintf("Program %s", getVersion())) 46 | fmt.Fprintln(os.Stdout) 47 | fmt.Fprintln(os.Stdout, fmt.Sprintf("Usage: %s [options]", os.Args[0])) 48 | fmt.Fprintln(os.Stdout, "Options:") 49 | flag.PrintDefaults() 50 | fmt.Fprintln(os.Stdout) 51 | fmt.Fprintln(os.Stdout, "This program is used to run as a service. To change the service behavior edit '/etc/default/samba_statusd' according to your needs.") 52 | } 53 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/consolelogger.go: -------------------------------------------------------------------------------- 1 | package commonbl 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "fmt" 10 | "os" 11 | "strings" 12 | ) 13 | 14 | // ConsoleLogger - A "class" with log functions 15 | type ConsoleLogger struct { 16 | Verbose bool 17 | } 18 | 19 | // Get a new instance of the Logger 20 | func NewConsoleLogger(verbose bool) *ConsoleLogger { 21 | ret := ConsoleLogger{verbose} 22 | 23 | return &ret 24 | } 25 | 26 | // GetVerbose - Tell if logger is verbose or not 27 | func (logger *ConsoleLogger) GetVerbose() bool { 28 | return logger.Verbose 29 | } 30 | 31 | // WriteInformation - Write a Info message to Stdout, will be prefixed with "Information: " 32 | func (logger *ConsoleLogger) WriteInformation(message string) { 33 | fmt.Fprintln(os.Stdout, fmt.Sprintf("Information: %s", message)) 34 | 35 | return 36 | } 37 | 38 | // WriteVerbose - Write a Verbose message to Stdout. Message will be written only if logger.Verbose is true. 39 | // The message will be prefixed with "Verbose :" 40 | func (logger *ConsoleLogger) WriteVerbose(message string) { 41 | if logger.Verbose { 42 | fmt.Fprintln(os.Stdout, fmt.Sprintf("Verbose: %s", message)) 43 | } 44 | 45 | return 46 | } 47 | 48 | // WriteErrorMessage - Write the message to Stderr. The Message will be prefixed with "Error: " 49 | func (logger *ConsoleLogger) WriteErrorMessage(message string) { 50 | trimmedMsg := strings.TrimPrefix(message, "Error: ") 51 | fmt.Fprintln(os.Stderr, fmt.Sprintf("Error: %s", trimmedMsg)) 52 | } 53 | 54 | // WriteError - Writes the err.Error() output to Stderr 55 | func (logger *ConsoleLogger) WriteError(err error) { 56 | trimmedMsg := strings.TrimPrefix(err.Error(), "Error: ") 57 | fmt.Fprintln(os.Stderr, fmt.Sprintf("Error: %s", trimmedMsg)) 58 | } 59 | 60 | // WriteError - Writes the 'err.Error() - addition' output to Stderr 61 | func (logger *ConsoleLogger) WriteErrorWithAddition(err error, addition string) { 62 | logger.WriteErrorMessage(fmt.Sprintf("%s - %s", err.Error(), addition)) 63 | } 64 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/consolelogger_test.go: -------------------------------------------------------------------------------- 1 | package commonbl 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "testing" 10 | ) 11 | 12 | func TestNewConsoleLogger(t *testing.T) { 13 | logger := NewConsoleLogger(false) 14 | if logger.Verbose == true { 15 | t.Errorf("Logger is verbose but should not") 16 | } 17 | 18 | logger = NewConsoleLogger(true) 19 | if logger.Verbose == false { 20 | t.Errorf("Logger is not verbose but should") 21 | } 22 | 23 | iLogger := Logger(logger) 24 | 25 | if iLogger.GetVerbose() == false { 26 | t.Errorf("Logger is not verbose but should") 27 | } 28 | 29 | logger.Verbose = false 30 | if iLogger.GetVerbose() == true { 31 | t.Errorf("Logger is verbose but not should") 32 | } 33 | } 34 | 35 | func TestWriteInformation(t *testing.T) { 36 | logger := NewConsoleLogger(false) 37 | logger.WriteInformation("My message") 38 | } 39 | 40 | func TestWriteErrorMessage(t *testing.T) { 41 | logger := NewConsoleLogger(false) 42 | logger.WriteErrorMessage("My message") 43 | } 44 | 45 | func TestWriteVerbose(t *testing.T) { 46 | logger := NewConsoleLogger(false) 47 | logger.WriteVerbose("My message 1") 48 | 49 | logger = NewConsoleLogger(true) 50 | logger.WriteVerbose("My message 2") 51 | } 52 | 53 | func TestWriteError(t *testing.T) { 54 | logger := NewConsoleLogger(false) 55 | err := NewReaderError("my data", LOCK_REQUEST, 3) 56 | 57 | logger.WriteError(err) 58 | } 59 | 60 | func TestWriteErrorWithAddition(t *testing.T) { 61 | logger := NewConsoleLogger(false) 62 | err := NewReaderError("my data", LOCK_REQUEST, 3) 63 | 64 | logger.WriteErrorWithAddition(err, "additional data") 65 | } 66 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/error.go: -------------------------------------------------------------------------------- 1 | package commonbl 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import "fmt" 9 | 10 | // ReaderError - Error when trying to read from the buffer 11 | type ReaderError struct { 12 | err string 13 | Data string 14 | Request RequestType 15 | ID int 16 | } 17 | 18 | func (e *ReaderError) Error() string { // Implement the Error Interface for the ReaderError struct 19 | return fmt.Sprintf("Error: %s", e.err) 20 | } 21 | 22 | // NewReaderError- Get a new OutFileIsDirError struct 23 | func NewReaderError(data string, rType RequestType, id int) *ReaderError { 24 | return &ReaderError{fmt.Sprintf("The received data \"%s\" was not expected for reqest \"%s\" with ID %d", data, rType, id), data, rType, id} 25 | } 26 | 27 | // WriterError - Error when trying to write to the buffer 28 | type WriterError struct { 29 | err string 30 | // Data causing the error 31 | Data string 32 | } 33 | 34 | func (e *WriterError) Error() string { // Implement the Error Interface for the WriterError struct 35 | return fmt.Sprintf("Error: %s", e.err) 36 | } 37 | 38 | // NewWriterError- Get a new OutFileIsDirError struct 39 | func NewWriterError(data string) *WriterError { 40 | return &WriterError{fmt.Sprintf("The data \"%s\" was not written", data), data} 41 | } 42 | 43 | // UnexpectedRequestFormatError - Error when trying to read an unexpected request format 44 | type UnexpectedRequestFormatError struct { 45 | err string 46 | // Data causing the error 47 | Request string 48 | } 49 | 50 | func (e *UnexpectedRequestFormatError) Error() string { // Implement the Error Interface for the UnexpectedRequestFormatError struct 51 | return fmt.Sprintf("Error: %s", e.err) 52 | } 53 | 54 | // NewUnexpectedRequestFormatError- Get a new UnexpectedRequestFormatError struct 55 | func NewUnexpectedRequestFormatError(request string) *UnexpectedRequestFormatError { 56 | return &UnexpectedRequestFormatError{fmt.Sprintf("The request \"%s\" was not expected or in wrong format", request), request} 57 | } 58 | 59 | // UnexpectedResponseFormatError - Error when trying to read an unexpected request format 60 | type UnexpectedResponseFormatError struct { 61 | err string 62 | // Data causing the error 63 | Response string 64 | } 65 | 66 | func (e *UnexpectedResponseFormatError) Error() string { // Implement the Error Interface for the UnexpectedResponseFormatError struct 67 | return fmt.Sprintf("Error: %s", e.err) 68 | } 69 | 70 | // UnexpectedResponseFormatError- Get a new UnexpectedRequestFormatError struct 71 | func NewUnexpectedResponseFormatError(response string) *UnexpectedResponseFormatError { 72 | return &UnexpectedResponseFormatError{fmt.Sprintf("The response \"%s\" was not expected or in wrong format", response), response} 73 | } 74 | 75 | // EmptyStringQueueError - Error when trying to pull an item from an empty StringQueue 76 | type EmptyStringQueueError struct { 77 | err string 78 | } 79 | 80 | func (e *EmptyStringQueueError) Error() string { // Implement the Error Interface for the EmptyStringQueueError struct 81 | return fmt.Sprintf("Error: %s", e.err) 82 | } 83 | 84 | // UnexpectedResponseFormatError- Get a new UnexpectedRequestFormatError struct 85 | func NewEmptyStringQueueError() *EmptyStringQueueError { 86 | return &EmptyStringQueueError{"The StringQueue is empty, no elements to pull."} 87 | } 88 | 89 | // DirectoryNotExistError - Error when a directory that should be used does not exist 90 | type DirectoryNotExistError struct { 91 | err string 92 | DirectoryPath string 93 | } 94 | 95 | func NewDirectoryNotExistError(directoryPath string) *DirectoryNotExistError { 96 | return &DirectoryNotExistError{fmt.Sprintf("The directory '%s' does not exist.", directoryPath), directoryPath} 97 | } 98 | 99 | func (e *DirectoryNotExistError) Error() string { // Implement the Error Interface for the DirectoryNotExistError struct 100 | return fmt.Sprintf("Error: %s", e.err) 101 | } 102 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/error_test.go: -------------------------------------------------------------------------------- 1 | package commonbl 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "fmt" 10 | "strings" 11 | "testing" 12 | ) 13 | 14 | func TestReaderError(t *testing.T) { 15 | path := "/some/sample/path" 16 | id := 123 17 | rType := LOCK_REQUEST 18 | err := NewReaderError(path, rType, id) 19 | 20 | if err.Data != path { 21 | t.Errorf("The Data was %s, but %s was expected", err.Data, path) 22 | } 23 | 24 | if string(err.Request) != string(LOCK_REQUEST) { 25 | t.Errorf("The Request was %s, but %s was expected", err.Request, path) 26 | } 27 | 28 | if err.ID != id { 29 | t.Errorf("The ID was %d, but %d was expected", err.ID, id) 30 | } 31 | 32 | if strings.Contains(err.Error(), path) == false { 33 | t.Errorf("The error message of ReaderError does not contain the expected data") 34 | } 35 | 36 | if strings.Contains(err.Error(), string(rType)) == false { 37 | t.Errorf("The error message of ReaderError does not contain the expected request type") 38 | } 39 | 40 | if strings.Contains(err.Error(), fmt.Sprintf("%d", id)) == false { 41 | t.Errorf("The error message of ReaderError does not contain the expected request id") 42 | } 43 | } 44 | 45 | func TestWriterError(t *testing.T) { 46 | path := "/some/sample/path" 47 | err := NewWriterError(path) 48 | 49 | if err.Data != path { 50 | t.Errorf("The File was %s, but %s was expected", err.Data, path) 51 | } 52 | 53 | if strings.Contains(err.Error(), path) == false { 54 | t.Errorf("The error message of WriterError does not contain the expected data") 55 | } 56 | } 57 | 58 | func TestUnexpectedRequestFormatError(t *testing.T) { 59 | path := "/some/sample/path" 60 | err := NewUnexpectedRequestFormatError(path) 61 | 62 | if err.Request != path { 63 | t.Errorf("The File was %s, but %s was expected", err.Request, path) 64 | } 65 | 66 | if strings.Contains(err.Error(), path) == false { 67 | t.Errorf("The error message of WriterError does not contain the expected data") 68 | } 69 | } 70 | 71 | func TestDirectoryNotExistError(t *testing.T) { 72 | path := "/some/sample/path" 73 | err := NewDirectoryNotExistError(path) 74 | 75 | if err.DirectoryPath != path { 76 | t.Errorf("DirectoryNotExistError DirectoryPath path value is '%s', but '%s' is expected", err.DirectoryPath, path) 77 | } 78 | 79 | if strings.Contains(err.Error(), path) == false { 80 | t.Errorf("The error message of DirectoryNotExistError does not contain the expected data") 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/filelogger.go: -------------------------------------------------------------------------------- 1 | package commonbl 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "fmt" 10 | "log" 11 | "os" 12 | "path/filepath" 13 | "strings" 14 | ) 15 | 16 | // FileLogger - A "class" with log functions 17 | type FileLogger struct { 18 | Verbose bool 19 | FullFilePath string 20 | infoLogger *log.Logger 21 | verboseLogger *log.Logger 22 | errorLogger *log.Logger 23 | } 24 | 25 | // Get a new instance of the Logger 26 | func NewFileLogger(verbose bool, fullFilePath string) (*FileLogger, error) { 27 | 28 | logFileDir := filepath.Dir(fullFilePath) 29 | if !directoryExists(logFileDir) { 30 | return nil, NewDirectoryNotExistError(logFileDir) 31 | } 32 | 33 | // If the file doesn't exist, create it or append to the file 34 | file, err := os.OpenFile(fullFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0666) 35 | if err != nil { 36 | return nil, err 37 | } 38 | infoLogger := log.New(file, "Information: ", log.LstdFlags|log.Lmsgprefix /*|log.Lmicroseconds*/) 39 | verboseLogger := log.New(file, "Verbose: ", log.LstdFlags|log.Lmsgprefix /*|log.Lmicroseconds*/) 40 | errorLogger := log.New(file, "Error: ", log.LstdFlags|log.Lmsgprefix /*|log.Lmicroseconds*/) 41 | 42 | ret := FileLogger{verbose, fullFilePath, infoLogger, verboseLogger, errorLogger} 43 | 44 | return &ret, nil 45 | } 46 | 47 | // GetVerbose - Tell if logger is verbose or not 48 | func (logger *FileLogger) GetVerbose() bool { 49 | return logger.Verbose 50 | } 51 | 52 | // WriteInformation - Write a Info message to Stdout, will be prefixed with "Information: " 53 | func (logger *FileLogger) WriteInformation(message string) { 54 | logger.infoLogger.Println(message) 55 | } 56 | 57 | // WriteVerbose - Write a Verbose message to Stdout. Message will be written only if logger.Verbose is true. 58 | // The message will be prefixed with "Verbose :" 59 | func (logger *FileLogger) WriteVerbose(message string) { 60 | if logger.Verbose { 61 | logger.verboseLogger.Println(message) 62 | } 63 | 64 | } 65 | 66 | // WriteErrorMessage - Write the message to Stderr. The Message will be prefixed with "Error: " 67 | func (logger *FileLogger) WriteErrorMessage(message string) { 68 | trimedMsg := strings.TrimPrefix(message, "Error: ") 69 | logger.errorLogger.Println(trimedMsg) 70 | } 71 | 72 | // WriteError - Writes the err.Error() output to Stderr 73 | func (logger *FileLogger) WriteError(err error) { 74 | trimedMsg := strings.TrimPrefix(err.Error(), "Error: ") 75 | logger.errorLogger.Println(trimedMsg) 76 | } 77 | 78 | // WriteError - Writes the 'err.Error() - addition' output to Stderr 79 | func (logger *FileLogger) WriteErrorWithAddition(err error, addition string) { 80 | logger.WriteErrorMessage(fmt.Sprintf("%s - %s", err.Error(), addition)) 81 | } 82 | 83 | func directoryExists(path string) bool { 84 | if stat, err := os.Stat(path); err == nil && stat.IsDir() { 85 | return true 86 | } 87 | 88 | return false 89 | } 90 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/go.mod: -------------------------------------------------------------------------------- 1 | module tobi.backfrak.de/internal/commonbl -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/loggerinterface.go: -------------------------------------------------------------------------------- 1 | package commonbl 2 | 3 | import "strings" 4 | 5 | // Logger - Interface for logger implementations 6 | type Logger interface { 7 | // GetVerbose - Tell if logger is verbose or not 8 | GetVerbose() bool 9 | 10 | // WriteInformation - Write a Info message to Stdout, will be prefixed with "Information: " 11 | WriteInformation(message string) 12 | 13 | // WriteVerbose - Write a Verbose message to Stdout. Message will be written only if logger.Verbose is true. 14 | // The message will be prefixed with "Verbose :" 15 | WriteVerbose(message string) 16 | 17 | // WriteErrorMessage - Write the message to Stderr. The Message will be prefixed with "Error: " 18 | WriteErrorMessage(message string) 19 | 20 | // WriteError - Writes the err.Error() output to Stderr 21 | WriteError(err error) 22 | 23 | // WriteError - Writes the 'err.Error() - addition' output to Stderr 24 | WriteErrorWithAddition(err error, addition string) 25 | } 26 | 27 | // Get the right logger depending on the input parameters 28 | func GetLogger(logFilePath string, verbose bool) (Logger, error) { 29 | trimmedPath := strings.TrimSpace(logFilePath) 30 | if trimmedPath != "" { 31 | return NewFileLogger(verbose, trimmedPath) 32 | } 33 | 34 | return NewConsoleLogger(verbose), nil 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/loggerinterface_test.go: -------------------------------------------------------------------------------- 1 | package commonbl 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | ) 7 | 8 | func TestGetLoggerForFileLogger(t *testing.T) { 9 | mutex.Lock() 10 | defer mutex.Unlock() 11 | ensureLogFileDirExists() 12 | logger, err := GetLogger(logfile_path, false) 13 | 14 | if err != nil { 15 | t.Errorf("Got error '%s' but expected none", err.Error()) 16 | } 17 | 18 | if logger.GetVerbose() == true { 19 | t.Errorf("The logger is verbose, but should not") 20 | } 21 | 22 | switch logger.(type) { 23 | case *FileLogger: 24 | fmt.Println("OK") 25 | default: 26 | t.Errorf("The logger is not the expected FileLogger") 27 | } 28 | 29 | logger2, err2 := GetLogger(logfile_path, true) 30 | if err2 != nil { 31 | t.Errorf("Got error '%s' but expected none", err2.Error()) 32 | } 33 | 34 | if logger2.GetVerbose() == false { 35 | t.Errorf("The logger is not verbose, but should ") 36 | } 37 | 38 | switch logger2.(type) { 39 | case *FileLogger: 40 | fmt.Println("OK") 41 | default: 42 | t.Errorf("The logger is not the expected FileLogger") 43 | } 44 | } 45 | 46 | func TestGetLoggerForConsoleLogger(t *testing.T) { 47 | logger1, err1 := GetLogger(" ", false) 48 | 49 | if err1 != nil { 50 | t.Errorf("Got error '%s' but expected none", err1.Error()) 51 | } 52 | 53 | if logger1.GetVerbose() == true { 54 | t.Errorf("The logger is verbose, but should not") 55 | } 56 | 57 | switch logger1.(type) { 58 | case *ConsoleLogger: 59 | fmt.Println("OK") 60 | default: 61 | t.Errorf("The logger is not the expected ConsoleLogger") 62 | } 63 | 64 | logger2, err2 := GetLogger(" ", true) 65 | if err2 != nil { 66 | t.Errorf("Got error '%s' but expected none", err2.Error()) 67 | } 68 | 69 | if logger2.GetVerbose() == false { 70 | t.Errorf("The logger is not verbose, but should ") 71 | } 72 | 73 | switch logger2.(type) { 74 | case *ConsoleLogger: 75 | fmt.Println("OK") 76 | default: 77 | t.Errorf("The logger is not the expected ConsoleLogger") 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/parameters.go: -------------------------------------------------------------------------------- 1 | package commonbl 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | // Parmeters - Data structure that stores the common paramters for the executables in this appalication 9 | type Parmeters struct { 10 | PrintVersion bool 11 | Verbose bool 12 | Help bool 13 | Test bool 14 | LogFilePath string 15 | } 16 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/pipes.go: -------------------------------------------------------------------------------- 1 | package commonbl 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "bufio" 10 | "fmt" 11 | "io" 12 | "os" 13 | "strings" 14 | "sync" 15 | "syscall" 16 | ) 17 | 18 | type PipeTypeT string 19 | 20 | const requestPipeFileName = "samba_exporter.request.pipe" 21 | const responsePipeFileName = "samba_exporter.response.pipe" 22 | const pipePath = "/run" 23 | const testPipePath = "/dev/shm" 24 | const pipePermission = 0660 25 | const endByte byte = 0 26 | 27 | const ( 28 | RequestPipe PipeTypeT = "REQUEST_PIPE" 29 | ResposePipe PipeTypeT = "RESPONSE_PIPE" 30 | ) 31 | 32 | // PipeHandler - Type to handle the pipe for comunication between samba_exporter and samba_statusd 33 | type PipeHandler struct { 34 | TestMode bool 35 | PipeType PipeTypeT 36 | mMutext sync.Mutex 37 | } 38 | 39 | // NewPipeHandler - Get a new instance of the PipeHandler type 40 | func NewPipeHandler(testMode bool, pipeType PipeTypeT) *PipeHandler { 41 | retVal := PipeHandler{} 42 | retVal.TestMode = testMode 43 | retVal.PipeType = pipeType 44 | 45 | return &retVal 46 | } 47 | 48 | // GetPipeFilePath - Get the path to the named pipe files for this application 49 | func (handler *PipeHandler) GetPipeFilePath() string { 50 | var dirname string 51 | if handler.TestMode { 52 | dirname = testPipePath 53 | } else { 54 | dirname = pipePath 55 | } 56 | 57 | var pipeFileName string 58 | if handler.PipeType == RequestPipe { 59 | pipeFileName = requestPipeFileName 60 | } else { 61 | pipeFileName = responsePipeFileName 62 | } 63 | 64 | return fmt.Sprintf("%s/%s", dirname, pipeFileName) 65 | } 66 | 67 | // PipeExists - Check if the named pipe files for this application exists 68 | func (handler *PipeHandler) PipeExists() bool { 69 | return FileExists(handler.GetPipeFilePath()) 70 | } 71 | 72 | // WaitForPipeInputBytes - Blocking! Wait for input in the pipe and return it as byte array 73 | // The array will be empty in case of errors 74 | func (handler *PipeHandler) WaitForPipeInputBytes() ([]byte, error) { 75 | handler.mMutext.Lock() 76 | defer handler.mMutext.Unlock() 77 | 78 | reader, errGet := handler.getReaderPipe() 79 | if errGet != nil { 80 | return []byte{}, errGet 81 | } 82 | received, errRead := reader.ReadBytes(endByte) 83 | if errRead != nil { 84 | if errRead != io.EOF { 85 | return []byte{}, errRead 86 | } 87 | return received, nil 88 | } 89 | 90 | return received[0 : len(received)-1], nil 91 | } 92 | 93 | // WaitForPipeInputString - Blocking! Wait for input in the pipe and return it as string 94 | // The string will be empty in case of errors 95 | func (handler *PipeHandler) WaitForPipeInputString() (string, error) { 96 | data, err := handler.WaitForPipeInputBytes() 97 | 98 | return strings.TrimSpace(string(data)), err 99 | } 100 | 101 | // WritePipeBytes - Write byte data to the pipe 102 | func (handler *PipeHandler) WritePipeBytes(data []byte) error { 103 | handler.mMutext.Lock() 104 | defer handler.mMutext.Unlock() 105 | 106 | writer, errGet := handler.getWriterPipe() 107 | if errGet != nil { 108 | return errGet 109 | } 110 | data = append(data, endByte) 111 | _, errWrite := writer.Write(data) 112 | if errWrite != nil { 113 | return errWrite 114 | } 115 | errFlush := writer.Flush() 116 | if errFlush != nil { 117 | return errFlush 118 | } 119 | 120 | return nil 121 | } 122 | 123 | // WritePipeString - Write string data to the pipe 124 | func (handler *PipeHandler) WritePipeString(data string) error { 125 | return handler.WritePipeBytes([]byte(data)) 126 | } 127 | 128 | // FileExists - Check if a file exists. Return false in case the path does not exist or is a directory 129 | func FileExists(filename string) bool { 130 | info, err := os.Stat(filename) 131 | if os.IsNotExist(err) { 132 | return false 133 | } 134 | 135 | if info.IsDir() { 136 | return false 137 | } 138 | return true 139 | } 140 | 141 | // GetReaderPipe - Get a new reader for the common pipe. 142 | // Remember: This is a blocking call and will return once data can be read from the pipe 143 | func (handler *PipeHandler) getReaderPipe() (*bufio.Reader, error) { 144 | 145 | if !handler.PipeExists() { 146 | errCreate := handler.createPipe() 147 | if errCreate != nil { 148 | return nil, errCreate 149 | } 150 | } 151 | 152 | file, errOpen := os.OpenFile(handler.GetPipeFilePath(), os.O_CREATE, os.ModeNamedPipe) 153 | if errOpen != nil { 154 | return nil, errOpen 155 | } 156 | 157 | return bufio.NewReader(file), nil 158 | 159 | } 160 | 161 | // GetWriterPipe - Get a new writer for the common pipe. 162 | func (handler *PipeHandler) getWriterPipe() (*bufio.Writer, error) { 163 | 164 | if !handler.PipeExists() { 165 | errCreate := handler.createPipe() 166 | if errCreate != nil { 167 | return nil, errCreate 168 | } 169 | } 170 | 171 | file, errOpen := os.OpenFile(handler.GetPipeFilePath(), os.O_RDWR|os.O_CREATE, pipePermission) 172 | if errOpen != nil { 173 | return nil, errOpen 174 | } 175 | 176 | return bufio.NewWriter(file), nil 177 | } 178 | 179 | func (handler *PipeHandler) createPipe() error { 180 | return syscall.Mkfifo(handler.GetPipeFilePath(), pipePermission) 181 | } 182 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/pipes_test.go: -------------------------------------------------------------------------------- 1 | package commonbl 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "os" 10 | "sync" 11 | "testing" 12 | ) 13 | 14 | var testDataString = "Hello Word" 15 | var testData = []byte(testDataString) 16 | 17 | var flushed bool 18 | var mux sync.Mutex 19 | 20 | func TestNewPipeHandler(t *testing.T) { 21 | handler := NewPipeHandler(false, RequestPipe) 22 | 23 | path := handler.GetPipeFilePath() 24 | if path != "/run/samba_exporter.request.pipe" { 25 | t.Errorf("GetPipeFilePath() has not the expected value") 26 | } 27 | 28 | handler = NewPipeHandler(false, ResposePipe) 29 | 30 | path = handler.GetPipeFilePath() 31 | if path != "/run/samba_exporter.response.pipe" { 32 | t.Errorf("GetPipeFilePath() has not the expected value") 33 | } 34 | } 35 | 36 | func TestGetPipeFilePath(t *testing.T) { 37 | handler := NewPipeHandler(true, RequestPipe) 38 | path := handler.GetPipeFilePath() 39 | 40 | if path == "" { 41 | t.Errorf("GetPipeFilePath is empty") 42 | } 43 | } 44 | 45 | func TestPipeFileExists(t *testing.T) { 46 | handler := NewPipeHandler(true, RequestPipe) 47 | 48 | os.Remove(handler.GetPipeFilePath()) 49 | if handler.PipeExists() == true { 50 | t.Errorf("PipeExists is true but should not") 51 | } 52 | 53 | os.Create(handler.GetPipeFilePath()) 54 | if handler.PipeExists() == false { 55 | t.Errorf("PipeExists is false but should not") 56 | } 57 | 58 | } 59 | 60 | func TestGetWriterPipe(t *testing.T) { 61 | handler := NewPipeHandler(true, RequestPipe) 62 | defer os.Remove(handler.GetPipeFilePath()) 63 | 64 | writer, err := handler.getWriterPipe() 65 | if err != nil { 66 | t.Fatalf("Got error \"%s\" but expected none", err) 67 | } 68 | 69 | if writer == nil { 70 | t.Errorf("The writer is nil, but should but") 71 | } 72 | 73 | } 74 | 75 | func TestGetWriterPipeTwoTimes(t *testing.T) { 76 | handler := NewPipeHandler(true, RequestPipe) 77 | defer os.Remove(handler.GetPipeFilePath()) 78 | 79 | writer1, err1 := handler.getWriterPipe() 80 | if err1 != nil { 81 | t.Fatalf("Got error \"%s\" but expected none", err1) 82 | } 83 | 84 | if writer1 == nil { 85 | t.Errorf("The writer is nil, but should but") 86 | } 87 | 88 | writer2, err2 := handler.getWriterPipe() 89 | if err2 != nil { 90 | t.Fatalf("Got error \"%s\" but expected none", err2) 91 | } 92 | 93 | if writer2 == nil { 94 | t.Errorf("The writer is nil, but should but") 95 | } 96 | 97 | } 98 | 99 | func TestReadWriteData(t *testing.T) { 100 | handler := NewPipeHandler(true, RequestPipe) 101 | defer os.Remove(handler.GetPipeFilePath()) 102 | mux.Lock() 103 | go scheduleWriter(t) 104 | mux.Lock() 105 | defer mux.Unlock() 106 | 107 | data, err := handler.WaitForPipeInputBytes() 108 | if err != nil { 109 | t.Fatalf("Got error \"%s\" but expected none", err) 110 | } 111 | 112 | for i, _ := range data { 113 | if data[i] != testData[i] { 114 | t.Errorf("The received byte does not match the send byte at position %d", i) 115 | } 116 | } 117 | } 118 | 119 | func TestReadWriteStringData(t *testing.T) { 120 | handler := NewPipeHandler(true, RequestPipe) 121 | defer os.Remove(handler.GetPipeFilePath()) 122 | mux.Lock() 123 | go scheduleStringWriter(t) 124 | mux.Lock() 125 | defer mux.Unlock() 126 | 127 | data, err := handler.WaitForPipeInputString() 128 | if err != nil { 129 | t.Fatalf("Got error \"%s\" but expected none", err) 130 | } 131 | 132 | if data != testDataString { 133 | t.Errorf("The received string \"%s\" does not match the send string \"%s\"", data, testDataString) 134 | } 135 | } 136 | 137 | func TestReadWriteStringDataReuse(t *testing.T) { 138 | handler := NewPipeHandler(true, RequestPipe) 139 | defer os.Remove(handler.GetPipeFilePath()) 140 | mux.Lock() 141 | go scheduleStringWriter(t) 142 | mux.Lock() 143 | mux.Unlock() 144 | 145 | data, err := handler.WaitForPipeInputString() 146 | if err != nil { 147 | t.Fatalf("Got error \"%s\" but expected none", err) 148 | } 149 | 150 | if data != testDataString { 151 | t.Errorf("The received string \"%s\" does not match the send string \"%s\"", data, testDataString) 152 | } 153 | 154 | mux.Lock() 155 | go scheduleStringWriter(t) 156 | mux.Lock() 157 | defer mux.Unlock() 158 | 159 | data, err = handler.WaitForPipeInputString() 160 | if err != nil { 161 | t.Fatalf("Got error \"%s\" but expected none", err) 162 | } 163 | 164 | if data != testDataString { 165 | t.Errorf("The received string \"%s\" does not match the send string \"%s\"", data, testDataString) 166 | } 167 | } 168 | 169 | func scheduleWriter(t *testing.T) { 170 | defer mux.Unlock() 171 | 172 | handler := NewPipeHandler(true, RequestPipe) 173 | err := handler.WritePipeBytes(testData) 174 | if err != nil { 175 | t.Errorf("Got error \"%s\" but expected none", err) 176 | } 177 | } 178 | 179 | func scheduleStringWriter(t *testing.T) { 180 | defer mux.Unlock() 181 | 182 | handler := NewPipeHandler(true, RequestPipe) 183 | err := handler.WritePipeString(testDataString) 184 | if err != nil { 185 | t.Errorf("Got error \"%s\" but expected none", err) 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/protocol.go: -------------------------------------------------------------------------------- 1 | package commonbl 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "fmt" 10 | "strconv" 11 | "strings" 12 | ) 13 | 14 | type RequestType string 15 | 16 | // Request the smbd process report table 17 | const PROCESS_REQUEST RequestType = "PROCESS_REQUEST:" 18 | 19 | // Request the smbd services report table 20 | const SHARE_REQUEST RequestType = "SHARE_REQUEST:" 21 | 22 | // Request the smbd table of locked files 23 | const LOCK_REQUEST RequestType = "LOCK_REQUEST:" 24 | 25 | // Request the ps data of the smbd PIDs 26 | const PS_REQUEST RequestType = "PS_REQUEST:" 27 | 28 | // Normal response when no files are locked 29 | const NO_LOCKED_FILES = "No locked files" 30 | 31 | // Data struct for a psutil response 32 | type PsUtilPidData struct { 33 | PID int64 34 | CpuUsagePercent float64 35 | VirtualMemoryUsageBytes uint64 36 | VirtualMemoryUsagePercent float64 37 | IoCounterReadCount uint64 38 | IoCounterReadBytes uint64 39 | IoCounterWriteCount uint64 40 | IoCounterWriteBytes uint64 41 | OpenFilesCount uint64 42 | ThreadCount uint64 43 | } 44 | 45 | // Implement Stringer Interface for LockData 46 | func (pidData PsUtilPidData) String() string { 47 | return fmt.Sprintf("PID: %d; CPU Usage Percent: %f; VM Usage Bytes: %d; VM Usage Percent: %f; IO Read Count: %d; IO Read Bytes: %d; IO Write Count: %d; IO Write Bytes: %d; Open File Count: %d; Thread Count: %d", 48 | pidData.PID, pidData.CpuUsagePercent, pidData.VirtualMemoryUsageBytes, pidData.VirtualMemoryUsagePercent, 49 | pidData.IoCounterReadCount, pidData.IoCounterReadBytes, pidData.IoCounterWriteCount, pidData.IoCounterWriteBytes, 50 | pidData.OpenFilesCount, pidData.ThreadCount) 51 | } 52 | 53 | // GetIdFromRequest - Get the ID from a request telegram 54 | func GetIdFromRequest(request string) (int, error) { 55 | splitted := strings.Split(request, ":") 56 | 57 | if len(splitted) != 2 { 58 | return 0, NewUnexpectedRequestFormatError(request) 59 | } 60 | 61 | idStr := strings.TrimSpace(splitted[1]) 62 | id, errConv := strconv.Atoi(idStr) 63 | if errConv != nil { 64 | return 0, NewUnexpectedRequestFormatError(request) 65 | } 66 | 67 | return id, nil 68 | } 69 | 70 | // GetRequest - Get the request string 71 | func GetRequest(requestType RequestType, id int) string { 72 | return fmt.Sprintf("%s %d", requestType, id) 73 | } 74 | 75 | // GetTestResponseHeader - Get the header for a test response 76 | func GetTestResponseHeader(rType RequestType, id int) string { 77 | return fmt.Sprintf("%s Test Response for request %d", rType, id) 78 | } 79 | 80 | // GetResponseHeader - Get the header for a test response 81 | func GetResponseHeader(rType RequestType, id int) string { 82 | return fmt.Sprintf("%s Response for request %d", rType, id) 83 | } 84 | 85 | // GetResponse - Get the response string out of header and data 86 | func GetResponse(header string, data string) string { 87 | return fmt.Sprintf("%s\n%s", header, data) 88 | } 89 | 90 | // SplitResponse - Split a response string in header and data 91 | // Always use CheckResponseHeader to validate the returned header string before further processing 92 | func SplitResponse(response string) (string, string, error) { 93 | 94 | if !strings.Contains(response, "\n") { 95 | return strings.TrimSpace(response), "", nil 96 | } 97 | 98 | splitResponse := strings.SplitN(response, "\n", 2) 99 | 100 | if len(splitResponse) != 2 { 101 | return "", "", NewUnexpectedResponseFormatError(response) 102 | } 103 | 104 | header := splitResponse[0] 105 | data := splitResponse[1] 106 | 107 | return header, data, nil 108 | } 109 | 110 | // CheckResponseHeader - Check if a response is for a specific request 111 | func CheckResponseHeader(header string, rType RequestType, id int) bool { 112 | if !strings.HasPrefix(header+":", string(rType)) { 113 | return false 114 | } 115 | 116 | if !strings.Contains(header, fmt.Sprintf("Response for request %d", id)) { 117 | return false 118 | } 119 | 120 | return true 121 | } 122 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/protocol_test.go: -------------------------------------------------------------------------------- 1 | package commonbl 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "fmt" 10 | "strings" 11 | "testing" 12 | ) 13 | 14 | func TestGetIdFromRequest(t *testing.T) { 15 | id, err := GetIdFromRequest("bal: 23") 16 | 17 | if err != nil { 18 | t.Errorf("Got error \"%s\" but expected none", err) 19 | } 20 | 21 | if id != 23 { 22 | t.Errorf("The id \"%d\" is not the expected", id) 23 | } 24 | 25 | id, err = GetIdFromRequest("bal: 23: sert") 26 | if err == nil { 27 | t.Errorf("Got no error but expected one") 28 | } 29 | 30 | if id != 0 { 31 | t.Errorf("The id \"%d\" is not the expected", id) 32 | } 33 | 34 | id, err = GetIdFromRequest("bal: 23 sert") 35 | if err == nil { 36 | t.Errorf("Got no error but expected one") 37 | } 38 | 39 | if id != 0 { 40 | t.Errorf("The id \"%d\" is not the expected", id) 41 | } 42 | } 43 | 44 | func TestGetRequest(t *testing.T) { 45 | id := 23 46 | rType := RequestType("bal:") 47 | request := GetRequest(rType, id) 48 | 49 | if strings.Contains(request, string(rType)) == false { 50 | t.Errorf("The request does not contain the expected request type") 51 | } 52 | 53 | if strings.Contains(request, fmt.Sprintf("%d", id)) == false { 54 | t.Errorf("The request does not contain the expected id") 55 | } 56 | 57 | } 58 | 59 | func TestGetTestResponseHeader(t *testing.T) { 60 | id := 23 61 | rType := RequestType("bal:") 62 | request := GetTestResponseHeader(rType, id) 63 | 64 | if strings.Contains(request, string(rType)) == false { 65 | t.Errorf("The request does not contain the expected request type") 66 | } 67 | 68 | if strings.Contains(request, fmt.Sprintf("%d", id)) == false { 69 | t.Errorf("The request does not contain the expected id") 70 | } 71 | 72 | } 73 | 74 | func TestGetResponseHeader(t *testing.T) { 75 | id := 23 76 | rType := RequestType("bal:") 77 | request := GetResponseHeader(rType, id) 78 | 79 | if strings.Contains(request, string(rType)) == false { 80 | t.Errorf("The request does not contain the expected request type") 81 | } 82 | 83 | if strings.Contains(request, fmt.Sprintf("%d", id)) == false { 84 | t.Errorf("The request does not contain the expected id") 85 | } 86 | 87 | } 88 | 89 | func TestGetResponse(t *testing.T) { 90 | id := 23 91 | rType := RequestType("bal:") 92 | header := GetResponseHeader(rType, id) 93 | data := "my data\nis hot\nor not" 94 | 95 | response := GetResponse(header, data) 96 | 97 | rHeader, rData, err := SplitResponse(response) 98 | 99 | if err != nil { 100 | t.Errorf("Got error \"%s\" but expected none", err) 101 | } 102 | 103 | if rHeader != header { 104 | t.Errorf("The header is not the expected") 105 | } 106 | 107 | if rData != data { 108 | t.Errorf("The data is not the expected") 109 | } 110 | } 111 | 112 | func TestSplitResponseUnValid1(t *testing.T) { 113 | 114 | response := fmt.Sprintf("%s Response for id my data is hot or not", SHARE_REQUEST) 115 | 116 | header, data, err := SplitResponse(response) 117 | 118 | if CheckResponseHeader(header, SHARE_REQUEST, 2) { 119 | t.Errorf("The header is valid but should not") 120 | } 121 | if data != "" { 122 | t.Errorf("The data is not the expected") 123 | } 124 | 125 | if err != nil { 126 | t.Errorf("Got error but expected none") 127 | } 128 | } 129 | 130 | func TestSplitResponseUnValid2(t *testing.T) { 131 | 132 | 133 | id := 2 134 | response := fmt.Sprintf("BLA: Response for request %d", id) 135 | 136 | header, data, err := SplitResponse(response) 137 | 138 | if CheckResponseHeader(header, SHARE_REQUEST, id) { 139 | t.Errorf("The header is valid but should not") 140 | } 141 | if data != "" { 142 | t.Errorf("The data is not the expected") 143 | } 144 | 145 | if err != nil { 146 | t.Errorf("Got error but expected none") 147 | } 148 | } 149 | 150 | func TestSplitResponseEmpty1(t *testing.T) { 151 | 152 | id := 23 153 | rType := RequestType("bal:") 154 | header := GetResponseHeader(rType, id) 155 | data := " " 156 | 157 | response := GetResponse(header, data) 158 | 159 | rHeader, rData, err := SplitResponse(response) 160 | 161 | if err != nil { 162 | t.Errorf("Got error \"%s\" but expected none", err) 163 | } 164 | 165 | if rHeader != header { 166 | t.Errorf("The header is not the expected") 167 | } 168 | 169 | if rData != data { 170 | t.Errorf("The data is not the expected") 171 | } 172 | } 173 | 174 | func TestSplitResponseEmpty(t *testing.T) { 175 | 176 | id := 23 177 | rType := RequestType("bal:") 178 | header := GetResponseHeader(rType, id) 179 | data := " " 180 | 181 | response := header + data 182 | 183 | rHeader, rData, err := SplitResponse(response) 184 | 185 | if err != nil { 186 | t.Errorf("Got error \"%s\" but expected none", err) 187 | } 188 | 189 | if rHeader != header { 190 | t.Errorf("The header is not the expected") 191 | } 192 | 193 | if rData != "" { 194 | t.Errorf("The data is not the expected") 195 | } 196 | } 197 | 198 | func TestCheckResponseHeader(t *testing.T) { 199 | id := 23 200 | rType := RequestType("bal:") 201 | header := GetResponseHeader(rType, id) 202 | 203 | if CheckResponseHeader(header, rType, id) == false { 204 | t.Errorf("CheckResponseHeader is false, but expected true") 205 | } 206 | 207 | if CheckResponseHeader("my header", rType, id) == true { 208 | t.Errorf("CheckResponseHeader is true, but expected false") 209 | } 210 | 211 | } 212 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/queue.go: -------------------------------------------------------------------------------- 1 | package commonbl 2 | 3 | // Copyright 2022 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "container/list" 10 | "sync" 11 | ) 12 | 13 | // StringQueue, a type that represents a FI/FI Stack for strings 14 | type StringQueue struct { 15 | mList *list.List 16 | mMutex sync.Mutex 17 | } 18 | 19 | // Get a new empty instance of the StringQueue 20 | func NewStringQueue() *StringQueue { 21 | var queue StringQueue 22 | queue.mList = list.New() 23 | 24 | return &queue 25 | } 26 | 27 | // Push (add) a string to the StringQueue 28 | func (queue *StringQueue) Push(value string) { 29 | queue.mMutex.Lock() 30 | defer queue.mMutex.Unlock() 31 | queue.mList.PushBack(value) 32 | } 33 | 34 | // Pull (get and remove) a string from the StringQueue. 35 | // Returns an error when the Queue is empty 36 | func (queue *StringQueue) Pull() (string, error) { 37 | if queue.mList.Len() <= 0 { 38 | return "", NewEmptyStringQueueError() 39 | } 40 | var valueString string 41 | queue.mMutex.Lock() 42 | defer queue.mMutex.Unlock() 43 | 44 | e := queue.mList.Front() 45 | valueString = e.Value.(string) 46 | queue.mList.Remove(e) 47 | return valueString, nil 48 | } 49 | 50 | // Tell if the StringQueue is empty 51 | func (queue *StringQueue) IsEmpty() bool { 52 | return queue.mList.Len() <= 0 53 | } 54 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/queue_test.go: -------------------------------------------------------------------------------- 1 | package commonbl 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | "testing" 7 | ) 8 | 9 | // Copyright 2022 by tobi@backfrak.de. All 10 | // rights reserved. Use of this source code is governed 11 | // by a BSD-style license that can be found in the 12 | // LICENSE file. 13 | 14 | func TestNewStringQueue(t *testing.T) { 15 | qu := NewStringQueue() 16 | 17 | if qu.IsEmpty() == false { 18 | t.Errorf("The StringQueue is not empty right after creation") 19 | } 20 | 21 | _, err := qu.Pull() 22 | if err == nil { 23 | t.Errorf("Got no error when pull on empty queue") 24 | } 25 | 26 | switch err.(type) { 27 | case *EmptyStringQueueError: 28 | fmt.Println("OK") 29 | default: 30 | t.Errorf("Expected a EmptyStringQueueError, got a %s", reflect.TypeOf(err)) 31 | } 32 | } 33 | 34 | func TestStringQueue(t *testing.T) { 35 | 36 | var pull string 37 | var err error 38 | qu := NewStringQueue() 39 | 40 | if qu.IsEmpty() == false { 41 | t.Errorf("The StringQueue is not empty right after creation") 42 | } 43 | 44 | qu.Push("a") 45 | 46 | if qu.IsEmpty() == true { 47 | t.Errorf("The StringQueue is empty right after 1. push") 48 | } 49 | 50 | qu.Push("b") 51 | qu.Push("c") 52 | qu.Push("d") 53 | 54 | if qu.IsEmpty() == true { 55 | t.Errorf("The StringQueue is empty right after 4. push") 56 | } 57 | 58 | pull, err = qu.Pull() 59 | if err != nil { 60 | t.Errorf("Got unexpected error while pull for \"a\"") 61 | } 62 | if pull != "a" { 63 | t.Errorf("Got \"%s\", but expected \"%s\"", pull, "a") 64 | } 65 | 66 | pull, err = qu.Pull() 67 | if err != nil { 68 | t.Errorf("Got unexpected error while pull for \"b\"") 69 | } 70 | if pull != "b" { 71 | t.Errorf("Got \"%s\", but expected \"%s\"", pull, "b") 72 | } 73 | 74 | pull, err = qu.Pull() 75 | if err != nil { 76 | t.Errorf("Got unexpected error while pull for \"c\"") 77 | } 78 | if pull != "c" { 79 | t.Errorf("Got \"%s\", but expected \"%s\"", pull, "c") 80 | } 81 | 82 | if qu.IsEmpty() == true { 83 | t.Errorf("The StringQueue is empty right after 4. push and 3. pull ") 84 | } 85 | 86 | pull, err = qu.Pull() 87 | if err != nil { 88 | t.Errorf("Got unexpected error while pull for \"d\"") 89 | } 90 | if pull != "d" { 91 | t.Errorf("Got \"%s\", but expected \"%s\"", pull, "d") 92 | } 93 | 94 | if qu.IsEmpty() == false { 95 | t.Errorf("The StringQueue is not empty right after pulling all elements ") 96 | } 97 | _, err = qu.Pull() 98 | if err == nil { 99 | t.Errorf("Got no error when pull on empty queue") 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/commonbl/testResponse.go: -------------------------------------------------------------------------------- 1 | package commonbl 2 | 3 | import ( 4 | "encoding/json" 5 | ) 6 | 7 | // Copyright 2021 by tobi@backfrak.de. All 8 | // rights reserved. Use of this source code is governed 9 | // by a BSD-style license that can be found in the 10 | // LICENSE file. 11 | 12 | // Contains the test data for a Lock Response 13 | const TestLockResponse = ` 14 | Locked files: 15 | Pid User(ID) DenyMode Access R/W Oplock SharePath Name Time 16 | -------------------------------------------------------------------------------------------------- 17 | 1120 1080 DENY_NONE 0x80 RDONLY NONE /usr/share/data . Sun May 16 12:07:02 2021` 18 | 19 | // Contains the test data for a Service Response 20 | const TestShareResponse = ` 21 | Service pid Machine Connected at Encryption Signing 22 | --------------------------------------------------------------------------------------------- 23 | IPC$ 1119 192.168.1.242 Sun May 16 11:55:36 AM 2021 CEST - - ` 24 | 25 | // Contains the test data for a Process Response 26 | const TestProcessResponse = ` 27 | Samba version 4.11.6-Ubuntu 28 | PID Username Group Machine Protocol Version Encryption Signing 29 | ---------------------------------------------------------------------------------------------------------------------------------------- 30 | 1117 1080 117 192.168.1.242 (ipv4:192.168.1.242:42296) SMB3_11 - partial(AES-128-CMAC)` 31 | 32 | func TestPsResponse() string { 33 | 34 | jsonData, _ := json.MarshalIndent(GetTestPsUtilPidData(), "", " ") 35 | 36 | return string(jsonData) 37 | } 38 | 39 | func TestPsResponseEmpty() string { 40 | 41 | jsonData, _ := json.MarshalIndent([]PsUtilPidData{}, "", " ") 42 | 43 | return string(jsonData) 44 | } 45 | 46 | // Always returns the same PsUtilPidData for test propose 47 | func GetTestPsUtilPidData() []PsUtilPidData { 48 | pidData := []PsUtilPidData{} 49 | pidData = append(pidData, PsUtilPidData{ 50 | 1234, 51 | 0.023, 52 | 456789, 53 | 0.0034, 54 | 123456, 55 | 789123, 56 | 2345, 57 | 6789, 58 | 1467, 59 | 8765, 60 | }) 61 | 62 | pidData = append(pidData, PsUtilPidData{ 63 | 4234, 64 | 0.123, 65 | 8789, 66 | 0.5034, 67 | 23456, 68 | 912378, 69 | 34576, 70 | 789543, 71 | 467123, 72 | 765853, 73 | }) 74 | 75 | return pidData 76 | } 77 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/smbexporterbl/pipecomunication/errors.go: -------------------------------------------------------------------------------- 1 | package pipecomunication 2 | 3 | import ( 4 | "fmt" 5 | 6 | "tobi.backfrak.de/internal/commonbl" 7 | ) 8 | 9 | // SmbStatusTimeOutError - Error when trying to get SMbStatus data runs into a timeout 10 | type SmbStatusTimeOutError struct { 11 | err string 12 | // Request - The request that causes this error 13 | Request commonbl.RequestType 14 | } 15 | 16 | func (e *SmbStatusTimeOutError) Error() string { // Implement the Error Interface for the SmbStatusTimeOutError struct 17 | return fmt.Sprintf("Error: %s", e.err) 18 | } 19 | 20 | // NewSmbStatusTimeOutError- Get a new SmbStatusTimeOutError struct 21 | func NewSmbStatusTimeOutError(request commonbl.RequestType) *SmbStatusTimeOutError { 22 | return &SmbStatusTimeOutError{fmt.Sprintf("The \"%s\" timed out", request), request} 23 | } 24 | 25 | // SmbStatusUnexpectedResponseError - Error when the SMbStatus data is unexpcted 26 | type SmbStatusUnexpectedResponseError struct { 27 | err string 28 | // Response - The Response that causes this error 29 | Response string 30 | } 31 | 32 | func (e *SmbStatusUnexpectedResponseError) Error() string { // Implement the Error Interface for the SmbStatusUnexpectedResponseError struct 33 | return fmt.Sprintf("Error: %s", e.err) 34 | } 35 | 36 | // NewSmbStatusUnexpectedResponseError - Get a new SmbStatusUnexpectedResponseError struct 37 | func NewSmbStatusUnexpectedResponseError(response string) *SmbStatusUnexpectedResponseError { 38 | return &SmbStatusUnexpectedResponseError{fmt.Sprintf("The response \"%s\" was not exptected", response), response} 39 | } 40 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/smbexporterbl/pipecomunication/errors_test.go: -------------------------------------------------------------------------------- 1 | package pipecomunication 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "strings" 10 | "testing" 11 | 12 | "tobi.backfrak.de/internal/commonbl" 13 | ) 14 | 15 | func TestSmbStatusTimeOutError(t *testing.T) { 16 | path := "/some/sample/path" 17 | err := NewSmbStatusTimeOutError(commonbl.RequestType(path)) 18 | 19 | if string(err.Request) != path { 20 | t.Errorf("The File was %s, but %s was expected", err.Request, path) 21 | } 22 | 23 | if strings.Contains(err.Error(), path) == false { 24 | t.Errorf("The error message of SmbStatusTimeOutError does not contain the expected request") 25 | } 26 | } 27 | 28 | func TestSmbStatusUnexpectedResponseError(t *testing.T) { 29 | path := "/some/sample/path" 30 | err := NewSmbStatusUnexpectedResponseError(path) 31 | 32 | if string(err.Response) != path { 33 | t.Errorf("The File was %s, but %s was expected", err.Response, path) 34 | } 35 | 36 | if strings.Contains(err.Error(), path) == false { 37 | t.Errorf("The error message of SmbStatusUnexpectedResponseError does not contain the expected request") 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/smbexporterbl/pipecomunication/go.mod: -------------------------------------------------------------------------------- 1 | module tobi.backfrak.de/internal/smbexporterbl/pipecomunication 2 | 3 | require tobi.backfrak.de/internal/commonbl v0.0.0 4 | replace tobi.backfrak.de/internal/commonbl v0.0.0 => ../../commonbl 5 | 6 | require tobi.backfrak.de/internal/smbexporterbl/smbstatusreader v0.0.0 7 | replace tobi.backfrak.de/internal/smbexporterbl/smbstatusreader v0.0.0 => ../smbstatusreader 8 | 9 | require tobi.backfrak.de/internal/smbstatusout v0.0.0 10 | replace tobi.backfrak.de/internal/smbstatusout v0.0.0 => ../../smbstatusout 11 | 12 | require tobi.backfrak.de/internal/testhelper v0.0.0 13 | replace tobi.backfrak.de/internal/testhelper v0.0.0 => ../../../internal/testhelper -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/smbexporterbl/pipecomunication/handler_test.go: -------------------------------------------------------------------------------- 1 | package pipecomunication 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "testing" 7 | 8 | "tobi.backfrak.de/internal/commonbl" 9 | "tobi.backfrak.de/internal/testhelper" 10 | ) 11 | 12 | // Copyright 2021 by tobi@backfrak.de. All 13 | // rights reserved. Use of this source code is governed 14 | // by a BSD-style license that can be found in the 15 | // LICENSE file. 16 | 17 | func TestGetSambaStatusTimeout(t *testing.T) { 18 | requestHandler := *commonbl.NewPipeHandler(true, commonbl.RequestPipe) 19 | responseHandler := *commonbl.NewPipeHandler(true, commonbl.ResposePipe) 20 | logger := *testhelper.NewTestLogger(true) 21 | _, _, _, _, err := GetSambaStatus(&requestHandler, &responseHandler, &logger, 2) 22 | 23 | if err == nil { 24 | t.Errorf("Exptected an error but got none") 25 | } 26 | 27 | switch err.(type) { 28 | case *SmbStatusTimeOutError: 29 | fmt.Fprintln(os.Stdout, "OK") 30 | default: 31 | t.Errorf("Got error '%s' type, but expected '*SmbStatusTimeOutError'", err.Error()) 32 | } 33 | 34 | if logger.GetOutputCount() != 3 { 35 | t.Errorf("The OutputCount '%d' is not the expected '3'", logger.GetOutputCount()) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/smbexporterbl/smbexporter/go.mod: -------------------------------------------------------------------------------- 1 | module tobi.backfrak.de/internal/smbexporterbl/smbexporter 2 | 3 | go 1.23 4 | 5 | require tobi.backfrak.de/internal/commonbl v0.0.0 6 | 7 | replace tobi.backfrak.de/internal/commonbl v0.0.0 => ../../commonbl 8 | 9 | require tobi.backfrak.de/internal/smbexporterbl/pipecomunication v0.0.0 10 | 11 | replace tobi.backfrak.de/internal/smbexporterbl/pipecomunication v0.0.0 => ../pipecomunication 12 | 13 | require tobi.backfrak.de/internal/smbexporterbl/statisticsGenerator v0.0.0 14 | 15 | replace tobi.backfrak.de/internal/smbexporterbl/statisticsGenerator v0.0.0 => ../statisticsGenerator 16 | 17 | require tobi.backfrak.de/internal/smbexporterbl/smbstatusreader v0.0.0 18 | 19 | replace tobi.backfrak.de/internal/smbexporterbl/smbstatusreader v0.0.0 => ../smbstatusreader 20 | 21 | require tobi.backfrak.de/internal/smbstatusout v0.0.0 22 | 23 | replace tobi.backfrak.de/internal/smbstatusout v0.0.0 => ../../smbstatusout 24 | 25 | require github.com/prometheus/client_golang v1.19.0 26 | 27 | require tobi.backfrak.de/internal/testhelper v0.0.0 28 | 29 | replace tobi.backfrak.de/internal/testhelper v0.0.0 => ../../../internal/testhelper 30 | 31 | require ( 32 | github.com/beorn7/perks v1.0.1 // indirect 33 | github.com/cespare/xxhash/v2 v2.2.0 // indirect 34 | github.com/prometheus/client_model v0.5.0 // indirect 35 | github.com/prometheus/common v0.48.0 // indirect 36 | github.com/prometheus/procfs v0.12.0 // indirect 37 | golang.org/x/sys v0.16.0 // indirect 38 | google.golang.org/protobuf v1.33.0 // indirect 39 | ) 40 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/smbexporterbl/smbexporter/go.sum: -------------------------------------------------------------------------------- 1 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 2 | github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= 3 | github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= 4 | github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= 5 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 6 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 7 | github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU= 8 | github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= 9 | github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= 10 | github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= 11 | github.com/prometheus/common v0.48.0 h1:QO8U2CdOzSn1BBsmXJXduaaW+dY/5QLjfB8svtSzKKE= 12 | github.com/prometheus/common v0.48.0/go.mod h1:0/KsvlIEfPQCQ5I2iNSAWKPZziNCvRs5EC6ILDTlAPc= 13 | github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= 14 | github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= 15 | golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= 16 | golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 17 | google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= 18 | google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= 19 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/smbexporterbl/smbstatusreader/go.mod: -------------------------------------------------------------------------------- 1 | module tobi.backfrak.de/internal/smbexporterbl/smbstatusreader 2 | 3 | require tobi.backfrak.de/internal/smbstatusout v0.0.0 4 | replace tobi.backfrak.de/internal/smbstatusout v0.0.0 => ../../smbstatusout 5 | 6 | require tobi.backfrak.de/internal/commonbl v0.0.0 7 | replace tobi.backfrak.de/internal/commonbl v0.0.0 => ../../commonbl 8 | 9 | require tobi.backfrak.de/internal/testhelper v0.0.0 10 | replace tobi.backfrak.de/internal/testhelper v0.0.0 => ../../../internal/testhelper 11 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/smbexporterbl/statisticsGenerator/go.mod: -------------------------------------------------------------------------------- 1 | 2 | module tobi.backfrak.de/internal/smbexporterbl/statisticsGenerator 3 | 4 | require tobi.backfrak.de/internal/smbexporterbl/smbstatusreader v0.0.0 5 | replace tobi.backfrak.de/internal/smbexporterbl/smbstatusreader v0.0.0 => ../smbstatusreader 6 | 7 | require tobi.backfrak.de/internal/smbstatusout v0.0.0 8 | replace tobi.backfrak.de/internal/smbstatusout v0.0.0 => ../../smbstatusout 9 | 10 | require tobi.backfrak.de/internal/commonbl v0.0.0 11 | replace tobi.backfrak.de/internal/commonbl v0.0.0 => ../../commonbl 12 | 13 | require tobi.backfrak.de/internal/testhelper v0.0.0 14 | replace tobi.backfrak.de/internal/testhelper v0.0.0 => ../../../internal/testhelper -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/smbstatusdbl/go.mod: -------------------------------------------------------------------------------- 1 | module tobi.backfrak.de/internal/smbstatusdbl 2 | 3 | go 1.23 4 | 5 | require ( 6 | github.com/shirou/gopsutil/v3 v3.23.2 7 | tobi.backfrak.de/internal/commonbl v0.0.0 8 | ) 9 | 10 | replace tobi.backfrak.de/internal/commonbl v0.0.0 => ../commonbl 11 | 12 | require ( 13 | github.com/go-ole/go-ole v1.2.6 // indirect 14 | github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect 15 | github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect 16 | github.com/tklauser/go-sysconf v0.3.11 // indirect 17 | github.com/tklauser/numcpus v0.6.0 // indirect 18 | github.com/yusufpapurcu/wmi v1.2.2 // indirect 19 | golang.org/x/sys v0.5.0 // indirect 20 | ) 21 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/smbstatusdbl/go.mod.gopsutil-v2: -------------------------------------------------------------------------------- 1 | module tobi.backfrak.de/internal/smbstatusdbl 2 | 3 | 4 | require tobi.backfrak.de/internal/commonbl v0.0.0 5 | replace tobi.backfrak.de/internal/commonbl v0.0.0 => ../commonbl 6 | 7 | require ( 8 | github.com/shirou/gopsutil v3.21.11+incompatible // indirect 9 | github.com/tklauser/go-sysconf v0.3.10 // indirect 10 | github.com/tklauser/numcpus v0.4.0 // indirect 11 | golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec // indirect 12 | ) 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/smbstatusdbl/go.sum: -------------------------------------------------------------------------------- 1 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 2 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 3 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 4 | github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= 5 | github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= 6 | github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 7 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 8 | github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 9 | github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= 10 | github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= 11 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 12 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 13 | github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= 14 | github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= 15 | github.com/shirou/gopsutil/v3 v3.23.2 h1:PAWSuiAszn7IhPMBtXsbSCafej7PqUOvY6YywlQUExU= 16 | github.com/shirou/gopsutil/v3 v3.23.2/go.mod h1:gv0aQw33GLo3pG8SiWKiQrbDzbRY1K80RyZJ7V4Th1M= 17 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 18 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 19 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 20 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 21 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 22 | github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= 23 | github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= 24 | github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= 25 | github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= 26 | github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= 27 | github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= 28 | github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= 29 | github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= 30 | golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 31 | golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 32 | golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 33 | golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= 34 | golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 35 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 36 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 37 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 38 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 39 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 40 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/smbstatusdbl/go.sum.gopsutil-v2: -------------------------------------------------------------------------------- 1 | github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= 2 | github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= 3 | github.com/tklauser/go-sysconf v0.3.10 h1:IJ1AZGZRWbY8T5Vfk04D9WOA5WSejdflXxP03OUqALw= 4 | github.com/tklauser/go-sysconf v0.3.10/go.mod h1:C8XykCvCb+Gn0oNCWPIlcb0RuglQTYaQ2hGm7jmxEFk= 5 | github.com/tklauser/numcpus v0.4.0 h1:E53Dm1HjH1/R2/aoCtXtPgzmElmn51aOkhCFSuZq//o= 6 | github.com/tklauser/numcpus v0.4.0/go.mod h1:1+UI3pD8NW14VMwdgJNJ1ESk2UnwhAnz5hMwiKKqXCQ= 7 | golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 8 | golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec h1:BkDtF2Ih9xZ7le9ndzTA7KJow28VbQW3odyk/8drmuI= 9 | golang.org/x/sys v0.0.0-20220928140112-f11e5e49a4ec/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 10 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/smbstatusdbl/psdatagenerator.go: -------------------------------------------------------------------------------- 1 | package smbstatusdbl 2 | 3 | // Copyright 2021 by tobi@backfrak.de. All 4 | // rights reserved. Use of this source code is governed 5 | // by a BSD-style license that can be found in the 6 | // LICENSE file. 7 | 8 | import ( 9 | "os/exec" 10 | "strconv" 11 | "strings" 12 | 13 | "github.com/shirou/gopsutil/v3/process" 14 | 15 | "tobi.backfrak.de/internal/commonbl" 16 | ) 17 | 18 | // Class to get commonbl.PsUtilPidData for a Process 19 | type PsDataGenerator struct { 20 | ProcessToRequest string 21 | pgrepPath string 22 | } 23 | 24 | // Get a new instance of PsDataGenerator 25 | func NewPsDataGenerator(processToRequest string) (*PsDataGenerator, error) { 26 | ret := PsDataGenerator{} 27 | var errLookPath error 28 | ret.ProcessToRequest = processToRequest 29 | ret.pgrepPath, errLookPath = exec.LookPath("pgrep") 30 | if errLookPath != nil { 31 | return nil, errLookPath 32 | } 33 | 34 | return &ret, nil 35 | } 36 | 37 | // Get the commonbl.PsUtilPidData data of the ProcessToRequest. 38 | // - In case this process is not running an empty list is returned 39 | // - In case an error, other then not finding the process, occurs during gathering data it is returned 40 | func (generator *PsDataGenerator) GetPsUtilPidData() ([]commonbl.PsUtilPidData, error) { 41 | ret := []commonbl.PsUtilPidData{} 42 | 43 | pidList, pidListErr := generator.getPidList() 44 | if (pidListErr != nil) || (len(pidList) == 0) { 45 | return ret, nil 46 | } 47 | 48 | for _, pid := range pidList { 49 | 50 | proc, errProc := process.NewProcess(pid) 51 | if errProc != nil { 52 | return nil, errProc 53 | } 54 | 55 | cpuPercent, errPer := proc.CPUPercent() 56 | if errPer != nil { 57 | return nil, errPer 58 | } 59 | vmBytes, errVmBytes := proc.MemoryInfo() 60 | if errVmBytes != nil { 61 | return nil, errVmBytes 62 | } 63 | vmPercent, errVmPercent := proc.MemoryPercent() 64 | if errVmPercent != nil { 65 | return nil, errVmPercent 66 | } 67 | ioCounters, errIoCounters := proc.IOCounters() 68 | if errIoCounters != nil { 69 | return nil, errIoCounters 70 | } 71 | openFileStats, errOpenFileStats := proc.OpenFiles() 72 | if errOpenFileStats != nil { 73 | return nil, errOpenFileStats 74 | } 75 | threadStats, errThreadStats := proc.Threads() 76 | if errThreadStats != nil { 77 | return nil, errThreadStats 78 | } 79 | 80 | entry := commonbl.PsUtilPidData{ 81 | int64(pid), 82 | cpuPercent, 83 | vmBytes.VMS, 84 | float64(vmPercent), 85 | ioCounters.ReadCount, 86 | ioCounters.ReadBytes, 87 | ioCounters.WriteCount, 88 | ioCounters.WriteBytes, 89 | uint64(len(openFileStats)), 90 | uint64(len(threadStats)), 91 | } 92 | 93 | ret = append(ret, entry) 94 | } 95 | 96 | return ret, nil 97 | } 98 | 99 | func (generator *PsDataGenerator) getPidList() ([]int32, error) { 100 | var pidList []int32 101 | 102 | pidListInByte, errGetPids := exec.Command(generator.pgrepPath, generator.ProcessToRequest).Output() 103 | if errGetPids != nil { 104 | return nil, errGetPids 105 | } 106 | 107 | pidListLines := strings.Split(string(pidListInByte), "\n") 108 | for _, line := range pidListLines { 109 | line = strings.TrimSpace(line) 110 | if line == "" { 111 | continue 112 | } 113 | pid, errConv := strconv.ParseInt(line, 10, 32) 114 | if errConv != nil { 115 | return nil, errConv 116 | } else { 117 | pidList = append(pidList, int32(pid)) 118 | } 119 | } 120 | 121 | return pidList, nil 122 | } 123 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/smbstatusdbl/psdatagenerator_test.go: -------------------------------------------------------------------------------- 1 | package smbstatusdbl 2 | 3 | import "testing" 4 | 5 | // Copyright 2021 by tobi@backfrak.de. All 6 | // rights reserved. Use of this source code is governed 7 | // by a BSD-style license that can be found in the 8 | // LICENSE file. 9 | 10 | func TestNewPsDataGenerator(t *testing.T) { 11 | processImage := "my_pid" 12 | sut, err := NewPsDataGenerator(processImage) 13 | if err != nil { 14 | t.Errorf("Error when getting a new PsDataGenerator") 15 | } 16 | 17 | if sut.ProcessToRequest != processImage { 18 | t.Errorf("The sut.ProcessToRequest '%s' is not the expected '%s'", sut.ProcessToRequest, processImage) 19 | } 20 | } 21 | 22 | func TestPsDataGeneratorNotRunningProcess(t *testing.T) { 23 | processImage := "my__not_existing_pid" 24 | sut, errNew := NewPsDataGenerator(processImage) 25 | if errNew != nil { 26 | t.Errorf("Error when getting a new PsDataGenerator: %s", errNew.Error()) 27 | } 28 | 29 | if sut.ProcessToRequest != processImage { 30 | t.Errorf("The sut.ProcessToRequest '%s' is not the expected '%s'", sut.ProcessToRequest, processImage) 31 | } 32 | 33 | pidList, errPidList := sut.getPidList() 34 | if errPidList == nil { 35 | t.Errorf("No error when getting a pid list for not running process image") 36 | } 37 | 38 | if len(pidList) != 0 { 39 | t.Errorf("Expected an empty list but got %d entries", len(pidList)) 40 | } 41 | 42 | pidData, errData := sut.GetPsUtilPidData() 43 | if errData != nil { 44 | t.Errorf("Error when getting a pid data: %s", errData.Error()) 45 | } 46 | 47 | if len(pidData) != 0 { 48 | t.Errorf("Expected an empty list but got %d entries", len(pidData)) 49 | } 50 | 51 | } 52 | 53 | func TestPsDataGeneratorRunningProcess(t *testing.T) { 54 | processImage := "go" 55 | sut, errNew := NewPsDataGenerator(processImage) 56 | if errNew != nil { 57 | t.Errorf("Error when getting a new PsDataGenerator: %s", errNew.Error()) 58 | } 59 | 60 | if sut.ProcessToRequest != processImage { 61 | t.Errorf("The sut.ProcessToRequest '%s' is not the expected '%s'", sut.ProcessToRequest, processImage) 62 | } 63 | 64 | pidList, errPidList := sut.getPidList() 65 | if errPidList != nil { 66 | t.Errorf("Error when getting a pid list for running process image '%s': %s", processImage, errPidList.Error()) 67 | } 68 | 69 | if len(pidList) == 0 { 70 | t.Errorf("Expected not an empty list") 71 | } 72 | 73 | // Disable this tests, since the latest ubuntu kernel seems to prevent normal users 74 | // from accessing /proc//io: 75 | // pidData, errData := sut.GetPsUtilPidData() 76 | // if errData != nil { 77 | // t.Errorf("Error when getting a pid data: %s", errData.Error()) 78 | // } 79 | 80 | // if len(pidData) == 0 { 81 | // t.Errorf("Expected not an empty list") 82 | // } 83 | 84 | // if len(pidData) != len(pidList) { 85 | // t.Errorf("Got '%d' data entries but '%d' pids", len(pidData), len(pidList)) 86 | // } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/smbstatusout/go.mod: -------------------------------------------------------------------------------- 1 | module tobi.backfrak.de/internal/smbstatusout -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/testhelper/go.mod: -------------------------------------------------------------------------------- 1 | module tobi.backfrak.de/internal/testhelper 2 | 3 | require tobi.backfrak.de/internal/commonbl v0.0.0 4 | 5 | replace tobi.backfrak.de/internal/commonbl v0.0.0 => ../../internal/commonbl -------------------------------------------------------------------------------- /src/tobi.backfrak.de/internal/testhelper/testlogger.go: -------------------------------------------------------------------------------- 1 | package testhelper 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | ) 7 | 8 | // TestLogger - A "class" with log functions 9 | type TestLogger struct { 10 | Verbose bool 11 | WrittenMessages []string 12 | WrittenErrors []string 13 | mutex sync.Mutex 14 | } 15 | 16 | // Get a new instance of the Logger 17 | func NewTestLogger(verbose bool) *TestLogger { 18 | writtenMessages := []string{} 19 | writtenErrors := []string{} 20 | mu := sync.Mutex{} 21 | ret := TestLogger{verbose, writtenMessages, writtenErrors, mu} 22 | 23 | return &ret 24 | } 25 | 26 | // GetVerbose - Tell if logger is verbose or not 27 | func (logger *TestLogger) GetVerbose() bool { 28 | return logger.Verbose 29 | } 30 | 31 | // GetErrorCount - Get the number of error messages written to stderr 32 | func (logger *TestLogger) GetErrorCount() int { 33 | return len(logger.WrittenErrors) 34 | } 35 | 36 | // GetMessageCount - Get the number of messages written to stdout 37 | func (logger *TestLogger) GetMessageCount() int { 38 | return len(logger.WrittenMessages) 39 | } 40 | 41 | // Get the number of messages written to any output stream 42 | func (logger *TestLogger) GetOutputCount() int { 43 | return len(logger.WrittenMessages) + len(logger.WrittenErrors) 44 | } 45 | 46 | // WriteInformation - Write a Info message to Stdout, will be prefixed with "Information: " 47 | func (logger *TestLogger) WriteInformation(message string) { 48 | logger.mutex.Lock() 49 | defer logger.mutex.Unlock() 50 | logger.WrittenMessages = append(logger.WrittenMessages, fmt.Sprintf("Information: %s", message)) 51 | 52 | return 53 | } 54 | 55 | // WriteVerbose - Write a Verbose message to Stdout. Message will be written only if logger.Verbose is true. 56 | // The message will be prefixed with "Verbose :" 57 | func (logger *TestLogger) WriteVerbose(message string) { 58 | if logger.Verbose { 59 | logger.mutex.Lock() 60 | defer logger.mutex.Unlock() 61 | logger.WrittenMessages = append(logger.WrittenMessages, fmt.Sprintf("Verbose: %s", message)) 62 | } 63 | 64 | return 65 | } 66 | 67 | // WriteErrorMessage - Write the message to Stderr. The Message will be prefixed with "Error: " 68 | func (logger *TestLogger) WriteErrorMessage(message string) { 69 | logger.mutex.Lock() 70 | defer logger.mutex.Unlock() 71 | logger.WrittenErrors = append(logger.WrittenErrors, fmt.Sprintf("Error: %s", message)) 72 | } 73 | 74 | // WriteError - Writes the err.Error() output to Stderr 75 | func (logger *TestLogger) WriteError(err error) { 76 | logger.mutex.Lock() 77 | defer logger.mutex.Unlock() 78 | logger.WrittenErrors = append(logger.WrittenErrors, err.Error()) 79 | } 80 | 81 | // WriteError - Writes the 'err.Error() - addition' output to Stderr 82 | func (logger *TestLogger) WriteErrorWithAddition(err error, addition string) { 83 | logger.mutex.Lock() 84 | defer logger.mutex.Unlock() 85 | logger.WrittenErrors = append(logger.WrittenErrors, fmt.Sprintf("%s - %s", err.Error(), addition)) 86 | } 87 | -------------------------------------------------------------------------------- /test/import/functions.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # ###################################################################################### 3 | # Copyright 2021 by tobi@backfrak.de. All 4 | # rights reserved. Use of this source code is governed 5 | # by a BSD-style license that can be found in the 6 | # LICENSE file. 7 | # ###################################################################################### 8 | # Functions used by the test scripts 9 | # ###################################################################################### 10 | 11 | function processWithNameIsRunning() { 12 | processName="$1" 13 | PID=$(pidof $processName) 14 | echo "PID of $processName $PID" 15 | if [ "$PID" == "" ]; then 16 | return 0 17 | else 18 | return 1 19 | fi 20 | } 21 | 22 | function fileExists() { 23 | path="$1" 24 | if [ -f "$path" ]; then 25 | echo "$path exists" 26 | return 1 27 | else 28 | echo "$path not found" 29 | return 0 30 | fi 31 | } -------------------------------------------------------------------------------- /test/installationTest/test.smb.conf: -------------------------------------------------------------------------------- 1 | # Samba configuration file, used during the CI/CD workflow installation tests 2 | [global] 3 | workgroup = exporter 4 | security = user 5 | map to guest = Bad Password 6 | 7 | [homes] 8 | comment = Home Directories 9 | browsable = no 10 | read only = no 11 | create mode = 0750 12 | 13 | [test] 14 | browsable = yes 15 | read only = yes 16 | public = yes 17 | path = /srv/test 18 | writable = yes 19 | comment = exporter test share 20 | printable = no 21 | guest ok = yes -------------------------------------------------------------------------------- /test/integrationTest/docker/Dockerfile.bookworm: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by the github workflow to run integration tests 8 | # ###################################################################################### 9 | 10 | # Use the same ubuntu version as for main development for this test 11 | FROM debian:bookworm 12 | 13 | # Install needed packages 14 | RUN apt-get update && apt-get install -y wget curl coreutils mawk procps 15 | 16 | # Copy test scripts 17 | COPY test/integrationTest/scripts/RunIntegrationTests.sh /RunIntegrationTests.sh 18 | RUN chmod 777 /RunIntegrationTests.sh 19 | COPY test/import/functions.sh /functions.sh 20 | RUN chmod 777 /functions.sh 21 | 22 | # The bin/samba_exporter from build output is restored as bin/samba_exporter/samba_exporter 23 | RUN mkdir -p /samba_exporter 24 | COPY bin/samba_exporter /samba_exporter/ 25 | RUN chmod 777 /samba_exporter/samba_exporter 26 | 27 | # The bin/samba_statusd from build output is restored as bin/samba_statusd/samba_statusd 28 | RUN mkdir -p /samba_statusd 29 | COPY bin/samba_statusd /samba_statusd 30 | RUN chmod 777 /samba_statusd/samba_statusd 31 | -------------------------------------------------------------------------------- /test/integrationTest/docker/Dockerfile.ubuntu: -------------------------------------------------------------------------------- 1 | # ###################################################################################### 2 | # Copyright 2021 by tobi@backfrak.de. All 3 | # rights reserved. Use of this source code is governed 4 | # by a BSD-style license that can be found in the 5 | # LICENSE file. 6 | # ###################################################################################### 7 | # Container image used by the github workflow to run integration tests 8 | # ###################################################################################### 9 | 10 | # Use the same ubuntu version as for main development for this test 11 | FROM ubuntu:noble 12 | 13 | # Install needed packages 14 | RUN apt-get update && apt-get install -y wget curl coreutils mawk procps 15 | 16 | # Copy test scripts 17 | COPY test/integrationTest/scripts/RunIntegrationTests.sh /RunIntegrationTests.sh 18 | RUN chmod 777 /RunIntegrationTests.sh 19 | COPY test/import/functions.sh /functions.sh 20 | RUN chmod 777 /functions.sh 21 | 22 | # The bin/samba_exporter from build output is restored as bin/samba_exporter/samba_exporter 23 | COPY bin/samba_exporter /samba_exporter 24 | RUN chmod 777 /samba_exporter/samba_exporter 25 | 26 | # The bin/samba_statusd from build output is restored as bin/samba_statusd/samba_statusd 27 | COPY bin/samba_statusd /samba_statusd 28 | RUN chmod 777 /samba_statusd/samba_statusd 29 | --------------------------------------------------------------------------------