docs: document project motivation, usage and scanner development
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ic762bb0d4b2fa619907a9e4f94278b5f6a6a6964
This commit is contained in:
parent
f96592a7cd
commit
040d620917
2 changed files with 270 additions and 0 deletions
60
docs/SCANNERS.md
Normal file
60
docs/SCANNERS.md
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# Creating a Custom Scanner
|
||||
|
||||
pscand comes with four scanners built-in, but you may easily create your own
|
||||
scanners for future extensibility. The process is simple.
|
||||
|
||||
1. Create your own crate
|
||||
2. Implement the `Scanner` trait
|
||||
3. Build, and place it into a scanner directory
|
||||
|
||||
See below:
|
||||
|
||||
## Creating your scanner crate
|
||||
|
||||
```toml
|
||||
# scanners/scanner-custom/Cargo.toml
|
||||
[package]
|
||||
name = "scanner-custom"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
pscand-core = { workspace = true }
|
||||
```
|
||||
|
||||
## Implementing the `Scanner` trait
|
||||
|
||||
```rust
|
||||
use pscand_core::scanner::Scanner;
|
||||
use pscand_macros::scanner;
|
||||
|
||||
pub struct CustomScanner;
|
||||
|
||||
impl Scanner for CustomScanner {
|
||||
fn name(&self) -> &str {
|
||||
"custom"
|
||||
}
|
||||
|
||||
fn collect(&self) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
|
||||
// Collect your metrics
|
||||
Ok(serde_json::json!({
|
||||
"value": 42
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
#[scanner]
|
||||
static SCANNER: CustomScanner = CustomScanner;
|
||||
```
|
||||
|
||||
## Building and installing
|
||||
|
||||
```bash
|
||||
cargo build --release
|
||||
# Install to a directory in PSCAND_SCANNER_DIRS (e.g., ~/.local/share/pscand/scanners)
|
||||
install -Dm755 target/release/libscanner_custom.so \
|
||||
~/.local/share/pscand/scanners/scanner-custom.so
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue