2016-08-24 08:12:20 +01:00
|
|
|
source: Developing/Code-Structure.md
|
2018-10-27 23:04:34 +01:00
|
|
|
path: blob/master/doc/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
2019-04-27 23:02:57 +02:00
|
|
|
# Code structure
|
2015-04-05 01:15:52 +01:00
|
|
|
|
2019-06-20 13:53:45 -05:00
|
|
|
This document will try and provide a good overview of how the code is
|
|
|
|
structured within LibreNMS. We will go through the main directories
|
|
|
|
and provide information on how and when they are used.
|
|
|
|
LibreNMS now uses [Laravel](https://laravel.com/docs/) for much of
|
|
|
|
it's frontend (webui) and database code. Much of the Laravel
|
|
|
|
documentation applies: <https://laravel.com/docs/structure>
|
2015-04-05 01:15:52 +01:00
|
|
|
|
2019-06-20 13:53:45 -05:00
|
|
|
Directories from the (filtered) structure tree below are some of the
|
|
|
|
directories that will be most interesting during development:
|
2019-04-27 23:02:57 +02:00
|
|
|
|
2019-10-21 02:47:40 +02:00
|
|
|
```text
|
2019-04-27 23:02:57 +02:00
|
|
|
.
|
|
|
|
├─ app
|
|
|
|
├─ database
|
|
|
|
│ └─ migrations
|
|
|
|
├─ doc
|
|
|
|
├─ html
|
|
|
|
│ ├─ css
|
|
|
|
│ │ └─ custom
|
|
|
|
│ └─ js
|
|
|
|
├─ includes
|
|
|
|
│ ├─ definitions
|
|
|
|
│ ├─ discovery
|
|
|
|
│ ├─ html
|
|
|
|
│ │ ├─ forms
|
|
|
|
│ │ ├─ graphs
|
|
|
|
│ │ ├─ pages
|
|
|
|
│ │ └─ reports
|
|
|
|
│ └─ polling
|
|
|
|
├─ LibreNMS
|
|
|
|
├─ logs
|
|
|
|
├─ mibs
|
|
|
|
└─ rrd
|
|
|
|
```
|
|
|
|
|
2015-04-05 01:15:52 +01:00
|
|
|
### doc/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
This is the location of all the documentation for LibreNMS, this is in
|
|
|
|
GitHub markdown format and can be viewed [online](http://docs.librenms.org/)
|
2016-08-21 08:07:14 -05:00
|
|
|
|
2019-01-14 07:44:23 -05:00
|
|
|
### app/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
2019-01-14 07:44:23 -05:00
|
|
|
Most Laravel and Eloquent classes should be under this directory.
|
|
|
|
|
2016-08-21 08:07:14 -05:00
|
|
|
### LibreNMS/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
Classes that don't belong to the Laravel application belong in this
|
|
|
|
directory, with a directory structure that matches the namespace. One
|
|
|
|
class per file. See [PSR-0](http://www.php-fig.org/psr/psr-0/) for details.
|
2015-04-05 01:15:52 +01:00
|
|
|
|
|
|
|
### html/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
All legacy web accessible files are located here. New pages should
|
|
|
|
follow the Laravel conventions.
|
|
|
|
|
2015-04-05 01:15:52 +01:00
|
|
|
### html/api_v0.php
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
This is the API routing file which directs users to the correct API
|
|
|
|
function based on the API endpoint call.
|
|
|
|
|
2015-04-05 01:15:52 +01:00
|
|
|
### html/index.php
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
This is the main file which all links within LibreNMS are parsed
|
|
|
|
through. It loads the majority of the relevant includes needed for the
|
|
|
|
control panel to function. CSS and JS files are also loaded here.
|
|
|
|
|
2019-04-27 23:02:57 +02:00
|
|
|
### html/css/
|
2019-10-21 02:47:40 +02:00
|
|
|
|
2019-04-27 23:02:57 +02:00
|
|
|
All used CSS files are located here.
|
2019-10-21 02:47:40 +02:00
|
|
|
|
2019-04-27 23:02:57 +02:00
|
|
|
### html/css/custom/
|
2019-10-21 02:47:40 +02:00
|
|
|
|
2019-04-27 23:02:57 +02:00
|
|
|
This is a directory you can put custom css files into that won't interfere with auto updates
|
2019-10-21 02:47:40 +02:00
|
|
|
|
2015-04-05 01:15:52 +01:00
|
|
|
### html/js/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
2019-01-14 07:44:23 -05:00
|
|
|
All used JS files are located here.
|
2015-04-05 01:15:52 +01:00
|
|
|
|
|
|
|
### includes/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
This directory is quite big and contains all the files to make the cli
|
|
|
|
and polling / discovery to work. This code is not currently
|
|
|
|
accessible from Laravel code (intentionally).
|
|
|
|
|
2015-04-05 01:15:52 +01:00
|
|
|
### includes/discovery/, includes/polling/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
All the discovery and polling code. The format is usually quite
|
|
|
|
similar between discovery and polling. Both are made up of modules and
|
|
|
|
the files within the relevant directories will match that module. So
|
|
|
|
for instance if you want to update the os detection for a device, you
|
|
|
|
would look in `includes/discovery/os/` for a file named after the
|
|
|
|
operating system such as linux:
|
|
|
|
`includes/discovery/linux.inc.php`. Within here you would update or
|
|
|
|
add support for newer OS'. This is the same for polling as well.
|
|
|
|
|
2019-04-27 23:02:57 +02:00
|
|
|
### includes/html/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
This is where the majority of the website core files are
|
|
|
|
located. These tend to be files that contain functions or often used
|
|
|
|
code segments that can be included where needed rather than
|
|
|
|
duplicating code.
|
|
|
|
|
2019-04-27 23:02:57 +02:00
|
|
|
### includes/html/forms/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
This directory contains all of the files that are dynamically included
|
|
|
|
from an ajax call to ajax/form.
|
|
|
|
|
2019-04-27 23:02:57 +02:00
|
|
|
### includes/html/api_functions.inc.php
|
2019-06-20 13:53:45 -05:00
|
|
|
|
2019-04-27 23:02:57 +02:00
|
|
|
All of the functions and calls for the API are located here.
|
2019-06-20 13:53:45 -05:00
|
|
|
|
2019-04-27 23:02:57 +02:00
|
|
|
### includes/html/functions.inc.php
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
This contains the majority of functions used throughout the standard
|
|
|
|
web ui.
|
|
|
|
|
2019-04-27 23:02:57 +02:00
|
|
|
### includes/html/graphs/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
This directory contains global and OS specific graph definitions.
|
|
|
|
|
2019-04-27 23:02:57 +02:00
|
|
|
### includes/html/reports/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
In here is a list of of files that generate PDF reports available to
|
|
|
|
the user. These are dynamically called in from `html/pdf.php` based on
|
|
|
|
the report the user requests.
|
|
|
|
|
2019-04-27 23:02:57 +02:00
|
|
|
### includes/html/table/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
This directory contains all of the ajax calls when generating the
|
|
|
|
table of data. Most have been converted over so if you are planning to
|
|
|
|
add a new table of data then you will do so here for all of the back
|
|
|
|
end data calls.
|
|
|
|
|
2019-04-27 23:02:57 +02:00
|
|
|
### includes/html/pages/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
This directory contains the URL structure when browsing the Web UI. So
|
|
|
|
for example `/devices/` is actually a call to
|
|
|
|
`includes/html/pages/devices.inc.php`, `/device/tab=ports/` is
|
|
|
|
`includes/html/pages/device/ports.inc.php`.
|
2015-04-05 01:15:52 +01:00
|
|
|
|
|
|
|
### logs/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
Contains the main librenms.log file by default, but can also contain
|
|
|
|
your web server's logs, poller logs, and other items.
|
2015-04-05 01:15:52 +01:00
|
|
|
|
|
|
|
### mibs/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
Here is where all of the mibs are located. Generally standard mibs
|
|
|
|
should be in the root directory and specific vendor mibs should be in
|
|
|
|
their own subdirectory.
|
2015-04-05 01:15:52 +01:00
|
|
|
|
|
|
|
### rrd/
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
Simple enough, this is where all of the rrd files are created. They
|
|
|
|
are stored in directory based on the device hostname.
|
2015-04-05 01:15:52 +01:00
|
|
|
|
2019-01-14 07:44:23 -05:00
|
|
|
### database/migrations
|
2019-06-20 13:53:45 -05:00
|
|
|
|
|
|
|
Contains all the database migrations. See Laravel docs for additional
|
|
|
|
info: <https://laravel.com/docs/migrations>
|
2019-01-17 09:00:25 -06:00
|
|
|
|
|
|
|
In general to create a new table you should run:
|
2019-06-20 13:53:45 -05:00
|
|
|
|
2019-01-17 09:00:25 -06:00
|
|
|
```bash
|
|
|
|
php artisan make:model ModelName -m -c -r
|
|
|
|
```
|