PHPackages                             iabdullahsk/laravel-health-nagios - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. iabdullahsk/laravel-health-nagios

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

iabdullahsk/laravel-health-nagios
=================================

Nagios integration for spatie/laravel-health

v1.2.1(7mo ago)07MITPHPPHP ^8.1

Since Sep 10Pushed 7mo agoCompare

[ Source](https://github.com/iabdullahsk/laravel-health-nagios)[ Packagist](https://packagist.org/packages/iabdullahsk/laravel-health-nagios)[ RSS](/packages/iabdullahsk-laravel-health-nagios/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (5)Used By (0)

Laravel Health Nagios
=====================

[](#laravel-health-nagios)

[![Latest Version on Packagist](https://camo.githubusercontent.com/495c3d819e25c1f68f6aca8b3e451689e304c21cc1514ca69eb1fbb10bdbf944/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f69616264756c6c6168736b2f6c61726176656c2d6865616c74682d6e6167696f732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iabdullahsk/laravel-health-nagios)[![Total Downloads](https://camo.githubusercontent.com/1a751abb1c9d33c969678dc533631ed85db2a8c17c680a222e0eb66829a3785a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f69616264756c6c6168736b2f6c61726176656c2d6865616c74682d6e6167696f732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iabdullahsk/laravel-health-nagios)[![Tests](https://camo.githubusercontent.com/07d6fdcd7aab3b1f3eef0309e28d7e6c17f9f989bfe9c4292c2f09cdb8524445/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f69616264756c6c6168736b2f6c61726176656c2d6865616c74682d6e6167696f732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/iabdullahsk/laravel-health-nagios/actions/workflows/run-tests.yml)

A Nagios integration add-on for [spatie/laravel-health](https://github.com/spatie/laravel-health). This package extends Laravel Health to provide Nagios-compatible monitoring endpoints and output formatting.

What This Package Does
----------------------

[](#what-this-package-does)

This add-on package provides:

- 🔍 **Nagios-Compatible Health Check Endpoint** - Exposes your Laravel Health checks in a format that Nagios can understand
- 🛡️ **Bearer Token Authentication** - Secure your health check endpoint with configurable bearer token authentication
- 📊 **Performance Data Generation** - Includes performance metrics for Nagios graphing and trending
- 🎯 **Proper Status Codes** - Returns appropriate HTTP status codes (200 for OK, 503 for failures)
- ⚙️ **Configurable Output** - Control what information is included in the Nagios output
- 🔄 **Fresh Results Support** - Option to force fresh health check execution via `?fresh` parameter

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10.0+, 11.0+, or 12.0+
- [spatie/laravel-health](https://github.com/spatie/laravel-health) ^1.0

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require iabdullahsk/laravel-health-nagios
```

**Note:** This will automatically install `spatie/laravel-health` as a dependency if it's not already installed.

### Publish Configuration (Optional)

[](#publish-configuration-optional)

```
php artisan vendor:publish --tag="nagios-config"
php artisan vendor:publish --tag="health-config"
```

The package will automatically register its service provider via Laravel's auto-discovery feature.

Configuration
-------------

[](#configuration)

### Environment Variables

[](#environment-variables)

Add these environment variables to your `.env` file:

```
# Enable/disable the Nagios endpoint
NAGIOS_ENABLED=true

# Bearer token for authentication (required for security)
NAGIOS_HEALTH_BEARER_TOKEN=your-secret-token-here

# Custom endpoint URL (optional)
NAGIOS_HEALTH_URL=/health/nagios

# Whether to always run fresh health checks
NAGIOS_ALWAYS_SEND_FRESH_RESULTS=true

# Include detailed information in output
NAGIOS_INCLUDE_DETAILS=true

# Include performance data for graphing
NAGIOS_INCLUDE_PERFORMANCE_DATA=true
```

### Configuration File

[](#configuration-file)

The published configuration file (`config/nagios.php`) provides additional options:

```
return [
    'enabled' => env('NAGIOS_ENABLED', false),
    'always_send_fresh_results' => env('NAGIOS_ALWAYS_SEND_FRESH_RESULTS', true),
    'enable_authentication' => env('NAGIOS_ENABLE_AUTHENTICATION', true),
    'bearer_token' => env('NAGIOS_HEALTH_BEARER_TOKEN'),
    'url' => env('NAGIOS_HEALTH_URL', '/health/nagios'),
    'middleware' => [
        Abdullah\LaravelHealthNagios\Http\Middleware\RequiresBearerToken::class,
    ],
    'include_details' => env('NAGIOS_INCLUDE_DETAILS', true),
    'include_performance_data' => env('NAGIOS_INCLUDE_PERFORMANCE_DATA', true),
];
```

Usage
-----

[](#usage)

### Basic Setup

[](#basic-setup)

Once installed and configured, your Nagios health check endpoint will be automatically available at the configured URL (default: `/health/nagios`).

### Example Output

[](#example-output)

**When all checks pass (HTTP 200):**

```
OK: 3 checks executed|'database'=1 'cache'=1 'queue'=1

database: Connection successful [OK]
cache: Cache working properly [OK]
queue: Jobs processing normally [OK]

```

**When checks fail (HTTP 503):**

```
CRITICAL: Connection failed|'database'=0 'cache'=1 'queue'=1

database: Connection failed [FAILED]
cache: Cache working properly [OK]
queue: Jobs processing normally [OK]

```

### Testing the Endpoint

[](#testing-the-endpoint)

```
# Test with bearer token
curl -H "Authorization: Bearer your-secret-token-here" \
     http://your-app.com/health/nagios

# Force fresh results
curl -H "Authorization: Bearer your-secret-token-here" \
     "http://your-app.com/health/nagios?fresh"
```

Integration with Laravel Health
-------------------------------

[](#integration-with-laravel-health)

This package works seamlessly with all existing Laravel Health checks. Simply configure your health checks as normal:

```
// In your Laravel application (e.g., AppServiceProvider)
use Spatie\Health\Facades\Health;
use Spatie\Health\Checks\Checks\UsedDiskSpaceCheck;
use Spatie\Health\Checks\Checks\DatabaseCheck;
use Spatie\Health\Checks\Checks\RedisCheck;

Health::checks([
    UsedDiskSpaceCheck::new(),
    DatabaseCheck::new(),
    RedisCheck::new(),
    // ... other health checks
]);
```

All configured health checks will automatically appear in the Nagios output.

Security Considerations
-----------------------

[](#security-considerations)

- **Always use bearer token authentication** in production environments
- **Use HTTPS** for your health check endpoints
- **Restrict network access** to your monitoring systems only
- **Use strong, unique tokens** for authentication

Development
-----------

[](#development)

### Running Tests

[](#running-tests)

The package includes comprehensive tests using [Pest](https://pestphp.com/), the same testing framework used by spatie/laravel-health.

#### Prerequisites

[](#prerequisites)

Make sure you have the development dependencies installed:

```
composer install
```

#### Running the Test Suite

[](#running-the-test-suite)

```
# Run all tests
./vendor/bin/pest

# Run tests with coverage
./vendor/bin/pest --coverage

# Run specific test files
./vendor/bin/pest tests/ResultFormats/NagiosResultsFormatTest.php

# Run tests with verbose output
./vendor/bin/pest --verbose
```

#### Test Structure

[](#test-structure)

The test suite includes:

- **Feature Tests** (`tests/Feature/`): Test service provider registration and configuration
- **Unit Tests** (`tests/Unit/`): Basic sanity checks and isolated component tests
- **HTTP Tests** (`tests/Http/Controllers/`): Test the Nagios endpoint functionality
- **Format Tests** (`tests/ResultFormats/`): Test Nagios output formatting

#### Test Coverage

[](#test-coverage)

The tests cover:

- ✅ Service provider registration and configuration loading
- ✅ Bearer token authentication middleware
- ✅ Nagios output formatting for different health check statuses
- ✅ HTTP endpoint responses and status codes
- ✅ Performance data generation
- ✅ Error handling for missing results

### Contributing

[](#contributing)

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Make your changes
4. Add or update tests as needed
5. Ensure all tests pass (`./vendor/bin/pest`)
6. Commit your changes (`git commit -m 'Add amazing feature'`)
7. Push to the branch (`git push origin feature/amazing-feature`)
8. Open a Pull Request

### Code Style

[](#code-style)

The package follows PSR-12 coding standards. You can check your code style using:

```
# Install PHP CS Fixer (if not already installed)
composer require --dev friendsofphp/php-cs-fixer

# Check code style
./vendor/bin/php-cs-fixer fix --dry-run --diff
```

Troubleshooting
---------------

[](#troubleshooting)

### Common Issues

[](#common-issues)

**Endpoint returns 404:**

- Check that `NAGIOS_ENABLED=true` in your `.env` file
- Verify that `NAGIOS_HEALTH_BEARER_TOKEN` is set
- Ensure the URL is correct (default: `/health/nagios`)

**Authentication fails:**

- Verify the bearer token in your request header: `Authorization: Bearer your-token`
- Check that the token matches your `NAGIOS_HEALTH_BEARER_TOKEN` environment variable

**No health check results:**

- Ensure you have configured health checks in your Laravel application
- Try adding `?fresh=1` to force fresh results
- Check Laravel logs for any health check errors

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing-1)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details on how to contribute to this project.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover a security vulnerability, please send an e-mail to \[\]. All security vulnerabilities will be promptly addressed.

Credits
-------

[](#credits)

- [Abdullah](https://github.com/abdullah)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Related Packages
----------------

[](#related-packages)

- [spatie/laravel-health](https://github.com/spatie/laravel-health) - The main Laravel Health package
- [spatie/laravel-health-ui](https://github.com/spatie/laravel-health-ui) - Web UI for Laravel Health

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance62

Regular maintenance activity

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~4 days

Total

4

Last Release

233d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/248c2aadefd45316b2223bde2679d33c25eed9acfe496e92e01ee43fefc23c5f?d=identicon)[iabdullahsk](/maintainers/iabdullahsk)

---

Top Contributors

[![iabdullahsk-easybell](https://avatars.githubusercontent.com/u/160482990?v=4)](https://github.com/iabdullahsk-easybell "iabdullahsk-easybell (6 commits)")

---

Tags

spatielaravelmonitoringhealthnagios

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/iabdullahsk-laravel-health-nagios/health.svg)

```
[![Health](https://phpackages.com/badges/iabdullahsk-laravel-health-nagios/health.svg)](https://phpackages.com/packages/iabdullahsk-laravel-health-nagios)
```

###  Alternatives

[spatie/laravel-activitylog

A very simple activity logger to monitor the users of your website or application

5.8k45.4M309](/packages/spatie-laravel-activitylog)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[rollbar/rollbar-laravel

Rollbar error monitoring integration for Laravel projects

14110.4M7](/packages/rollbar-rollbar-laravel)[inspector-apm/inspector-laravel

Code Execution Monitoring, built for developers.

2332.0M2](/packages/inspector-apm-inspector-laravel)[encodia/laravel-health-env-vars

Custom check for Spatie's Laravel Health - Ensure every .env variable you need has been set

20143.5k](/packages/encodia-laravel-health-env-vars)[muhammadsadeeq/laravel-activitylog-ui

A beautiful, modern UI for Spatie's Activity Log with advanced filtering, analytics, and real-time features.

17510.1k](/packages/muhammadsadeeq-laravel-activitylog-ui)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
