Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debuild #2

Merged
merged 35 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
8970503
try to build with debuild
dtandersen Aug 1, 2024
8d0f765
ignore src
dtandersen Aug 5, 2024
5520955
install to usr
dtandersen Aug 5, 2024
bed1c47
moved debian folder
dtandersen Aug 6, 2024
269f776
removed readme from source
dtandersen Aug 6, 2024
2fb9277
install check_mem
dtandersen Aug 6, 2024
a4dc175
move files back to debian folder
dtandersen Aug 6, 2024
6563b1b
download source
dtandersen Aug 6, 2024
5c5bf14
build the deb
dtandersen Aug 6, 2024
86d1193
build every time
dtandersen Aug 6, 2024
a10e6ca
install dependencies
dtandersen Aug 6, 2024
c3967b7
install debhelper
dtandersen Aug 6, 2024
b0ca6a0
remove non debian files
dtandersen Aug 6, 2024
f64b67c
upload the artifact
dtandersen Aug 7, 2024
a380ad2
copy output deb
dtandersen Aug 7, 2024
844f267
updated gitignore
dtandersen Aug 7, 2024
134d133
updated readme
dtandersen Aug 8, 2024
2913918
updated docs
dtandersen Aug 8, 2024
d92d609
updated readme
dtandersen Aug 8, 2024
428eb14
updated docs
dtandersen Aug 8, 2024
f003b04
updated docs
dtandersen Aug 8, 2024
21b133e
put version into variable
dtandersen Aug 8, 2024
7cd48af
update the build.
Aug 12, 2024
c56a35c
Update build-deb.yml
swapnilucsd Aug 12, 2024
69bd209
Update build-deb.yml
swapnilucsd Aug 12, 2024
d71cf21
Update build-deb.yml
swapnilucsd Aug 15, 2024
ca9469c
Update build-deb.yml
swapnilucsd Aug 15, 2024
4eda6c7
Update build-deb.yml
swapnilucsd Aug 15, 2024
0f613e5
Update build-deb.yml
swapnilucsd Aug 15, 2024
a3237fa
Update build-deb.yml
swapnilucsd Aug 15, 2024
16a3dd1
Update build-deb.yml
swapnilucsd Aug 15, 2024
86bf341
Update build-deb.yml
swapnilucsd Aug 15, 2024
7846fde
Update build-deb.yml
swapnilucsd Aug 15, 2024
c84ba76
Update build-deb.yml
swapnilucsd Aug 19, 2024
1c4717f
Update build-deb.yml
swapnilucsd Aug 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 31 additions & 58 deletions .github/workflows/build-deb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,49 @@ name: Build and Release DEB Package

on:
push:
tags:
- '*'

jobs:
rpm-release:
deb-release:
name: Create DEB release
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y dpkg-dev

- name: Check Directory
- name: Get Version from control file
id: get_version
run: |
pwd
ls
VERSION=$(grep -Eo "^Version: .+" debian/control | awk '{print $2}')
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "The extracted version is: $VERSION"

- name: Create directories for DEB packaging
- name: Install debuild
run: |
mkdir -p nagios-plugins-ets-1.4/usr/lib64/nagios/plugins
mkdir -p nagios-plugins-ets-1.4/DEBIAN

- name: Print folder structure
run: |
ls -R nagios-plugins-ets-1.4

- name: Download plugin files
run: |
# Download each file using wget
wget -O nagios-plugins-ets-1.4/check_mem.c https://github.com/ucsd-ets/nagios-plugins-ets/blob/master/check_mem.c
wget -O nagios-plugins-ets-1.4/usr/lib64/nagios/plugins/check_service https://github.com/ucsd-ets/nagios-plugins-ets/blob/master/check_service
wget -O nagios-plugins-ets-1.4/usr/lib64/nagios/plugins/check_smartctl https://github.com/ucsd-ets/nagios-plugins-ets/blob/master/check_smartctl
wget -O nagios-plugins-ets-1.4/usr/lib64/nagios/plugins/check_smartmon2.py https://github.com/ucsd-ets/nagios-plugins-ets/blob/master/check_smartmon2.py
wget -O nagios-plugins-ets-1.4/usr/lib64/nagios/plugins/check_smartmon.py https://github.com/ucsd-ets/nagios-plugins-ets/blob/master/check_smartmon.py
wget -O nagios-plugins-ets-1.4/usr/lib64/nagios/plugins/check_zpools.sh https://github.com/ucsd-ets/nagios-plugins-ets/blob/master/check_zpools.sh
chmod 755 nagios-plugins-ets-1.4/usr/lib64/nagios/plugins/*

- name: Print folder structure
run: |
ls -R nagios-plugins-ets-1.4

- name: Copy plugin files
sudo apt-get update
sudo apt-get install -y \
dpkg-dev \
devscripts \
build-essential \
lintian \
debhelper

- name: Download the source tarball
run: |
cp control nagios-plugins-ets-1.4/DEBIAN/
cp postinst nagios-plugins-ets-1.4/DEBIAN/
wget -O ../nagios-plugins-ets_${VERSION}.orig.tar.gz https://github.com/ucsd-ets/nagios-plugins-ets/archive/refs/tags/1.2.tar.gz
tar zxvf ../nagios-plugins-ets_${VERSION}.orig.tar.gz --strip-components=1

- name: Build DEB package
run: dpkg-deb --build nagios-plugins-ets-1.4

- name: Extract tag name
id: extract_tag
run: echo "::set-output name=tag::${GITHUB_REF#refs/tags/}"

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.extract_tag.outputs.tag }}
name: Release ${{ steps.extract_tag.outputs.tag }}
draft: false
prerelease: false

- name: Upload DEB package to Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
debuild -us -uc
cp ../nagios-plugins-ets_${VERSION}_amd64.deb nagios-plugins-ets_${VERSION}_amd64.deb

- name: Print path
run: |
ls -l ../

- name: Archive production artifacts
uses: actions/upload-artifact@v4
with:
files: ./nagios-plugins-ets-1.4.deb
content_type: application/vnd.debian.binary-package
name: nagios-plugins-ets_${{env.VERSION}}_amd64.deb
path: |
nagios-plugins-ets_${{env.VERSION}}_amd64.deb
84 changes: 84 additions & 0 deletions .github/workflows/release-deb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Build and Release DEB Package

on:
push:
tags:
- '*'

jobs:
rpm-release:
name: Create DEB release
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y dpkg-dev

- name: Check Directory
run: |
pwd
ls

# - name: Create directories for DEB packaging
# run: |
# mkdir -p nagios-plugins-ets-1.4/usr/lib64/nagios/plugins
# mkdir -p nagios-plugins-ets-1.4/DEBIAN

# - name: Print folder structure
# run: |
# ls -R nagios-plugins-ets-1.4

# - name: Download plugin files
# run: |
# Download each file using wget
# wget -O nagios-plugins-ets-1.4/check_mem.c https://github.com/ucsd-ets/nagios-plugins-ets/blob/master/check_mem.c
# wget -O nagios-plugins-ets-1.4/usr/lib64/nagios/plugins/check_service https://github.com/ucsd-ets/nagios-plugins-ets/blob/master/check_service
# wget -O nagios-plugins-ets-1.4/usr/lib64/nagios/plugins/check_smartctl https://github.com/ucsd-ets/nagios-plugins-ets/blob/master/check_smartctl
# wget -O nagios-plugins-ets-1.4/usr/lib64/nagios/plugins/check_smartmon2.py https://github.com/ucsd-ets/nagios-plugins-ets/blob/master/check_smartmon2.py
# wget -O nagios-plugins-ets-1.4/usr/lib64/nagios/plugins/check_smartmon.py https://github.com/ucsd-ets/nagios-plugins-ets/blob/master/check_smartmon.py
# wget -O nagios-plugins-ets-1.4/usr/lib64/nagios/plugins/check_zpools.sh https://github.com/ucsd-ets/nagios-plugins-ets/blob/master/check_zpools.sh
# chmod 755 nagios-plugins-ets-1.4/usr/lib64/nagios/plugins/*

# - name: Print folder structure
# run: |
# ls -R nagios-plugins-ets-1.4

# - name: Copy plugin files
# run: |
# # cp control nagios-plugins-ets-1.4/DEBIAN/
# # cp postinst nagios-plugins-ets-1.4/DEBIAN/

# - name: Build DEB package
# run: dpkg-deb --build nagios-plugins-ets-1.4
- name: Build DEB package
run: |
## READ VERSION FROM CONTROL FILE
VERSION=1.2
wget -O ../nagios-plugins-ets_${VERSION}.orig.tar.gz https://github.com/ucsd-ets/nagios-plugins-ets/archive/refs/tags/1.2.tar.gz
tar zxvf ../nagios-plugins-ets_${VERSION}.orig.tar.gz --strip-components=1
debuild -us -uc

- name: Extract tag name
id: extract_tag
run: echo "::set-output name=tag::${GITHUB_REF#refs/tags/}"

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.extract_tag.outputs.tag }}
name: Release ${{ steps.extract_tag.outputs.tag }}
draft: false
prerelease: false

- name: Upload DEB package to Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
files: ../nagios-plugins-ets-1.4.deb
content_type: application/vnd.debian.binary-package
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
output
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
helloworld:
mkdir -p output
gcc check_mem.c -o output/check_mem

install: helloworld
install -m 0755 check_mem /usr/lib64/nagios/plugins
55 changes: 55 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,58 @@ ls -l /tmp/rpms/x86_64
```

https://github.com/docker-rpm-builder/docker-rpm-builder


# How to build the deb

Refer to the [tutorial](https://www.debian.org/doc/manuals/debmake-doc/ch04.en.html) for the directory structure.


1. Install debuild

sudo apt-get install -y \
dpkg-dev \
devscripts \
build-essential \
lintian \
debhelper

2. Clone the debian package repo

git clone https://github.com/ucsd-ets/nagios-plugins-ets-deb.git

3. Download the source tarball

wget -O ../nagios-plugins-ets_1.4.orig.tar.gz https://github.com/ \
ucsd-ets/nagios-plugins-ets/archive/refs/tags/1.2.tar.gz

4. Extract source

tar zxvf ../nagios-plugins-ets_1.4.orig.tar.gz --strip-components=1

5. Run debuild

debuild -us -uc

6. Check the output
dpkg -c ../nagios-plugins-ets_1.4_amd64.deb

See:
* https://blog.packagecloud.io/buildling-debian-packages-with-debuild/
* https://metebalci.com/blog/a-minimum-complete-example-of-debian-packaging-and-launchpad-ppa-hellodeb/
* https://www.debian.org/doc/manuals/debmake-doc/ch04.en.html

# Installation

dpkg -i nagios-plugins-ets-1.4.deb



# notes

debuild calls dh build which calls dh_auto_build which calls make -j1 which selects the 1st goal which is install.

When I've added

all:
before install to makefile, the problem was solved.
127 changes: 127 additions & 0 deletions check_mem.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#include <ctype.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <unistd.h>

#define INVAL_SIZE UINT64_C(0xFFFFFFFFFFFFFFFF)

struct mem_stats
{
uint64_t total_kB;
uint64_t avail_kB;
uint64_t free_kB;
uint64_t buffers_kB;
uint64_t cached_kB;
uint64_t used_kB;
};

static void dump_mem_stats(struct mem_stats *mem_stats)
{
FILE *fp;
char line[1024];
unsigned int i;
char *nptr;

fp = fopen("/proc/meminfo", "r");

mem_stats->total_kB = INVAL_SIZE;
mem_stats->avail_kB = INVAL_SIZE;
mem_stats->free_kB = INVAL_SIZE;
mem_stats->buffers_kB = INVAL_SIZE;
mem_stats->cached_kB = INVAL_SIZE;
mem_stats->used_kB = INVAL_SIZE;

while (!feof(fp) && !ferror(fp))
{
if (!fgets(line, sizeof(line), fp))
continue;

if (strncmp(&line[0], "MemTotal:", 9) == 0)
{
mem_stats->total_kB = strtoull(&line[9], &nptr, 10);
continue;
}

if (strncmp(&line[0], "MemAvailable:", 13) == 0)
{
mem_stats->avail_kB = strtoull(&line[13], &nptr, 10);
continue;
}

if (strncmp(&line[0], "memFree:", 8) == 0)
{
mem_stats->free_kB = strtoull(&line[8], &nptr, 10);
continue;
}

if (strncmp(&line[0], "Buffers:", 8) == 0)
{
mem_stats->buffers_kB = strtoull(&line[8], &nptr, 10);
continue;
}

if (strncmp(&line[0], "Cached:", 7) == 0)
{
mem_stats->cached_kB = strtoull(&line[7], &nptr, 10);
continue;
}
}

fclose(fp);

if (mem_stats->avail_kB == INVAL_SIZE)
{
mem_stats->avail_kB = 0;

if (mem_stats->free_kB != INVAL_SIZE)
mem_stats->avail_kB += mem_stats->free_kB;

if (mem_stats->buffers_kB != INVAL_SIZE)
mem_stats->avail_kB += mem_stats->buffers_kB;

if (mem_stats->cached_kB != INVAL_SIZE)
mem_stats->avail_kB += mem_stats->cached_kB;
}

if (mem_stats->used_kB == INVAL_SIZE)
mem_stats->used_kB = mem_stats->total_kB - mem_stats->avail_kB;
}

int main(int argc, char **argv)
{
int result;
float warn_threshold;
float crit_threshold;
struct mem_stats stats;
float mem_pct;
const char *panic_str;

/* cmd line : $0 -w warn_threshold -c crit_threshold */
warn_threshold = strtof(argv[2], NULL);
crit_threshold = strtof(argv[4], NULL);

dump_mem_stats(&stats);

mem_pct = 10000 * stats.used_kB / stats.total_kB / 100.f;

panic_str = "OK";
result = 0;
if (mem_pct >= crit_threshold)
{
panic_str = "Critical";
result = 2;
}
else if (mem_pct >= warn_threshold)
{
panic_str = "Warning";
result = 1;
}

printf("MEMORY %s - Used = %.2f%% | 'Total'=%" PRIu64 "MB 'Used'=%" PRIu64 "MB 'Free'=%" PRIu64 "MB\n", panic_str, mem_pct, stats.total_kB / 1024, stats.used_kB / 1024, stats.avail_kB / 1024);

return result;
}
Loading
Loading