Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ steps:
- name: build for Linux
image: rust:latest
commands:
- apt-get update && apt-get install libprocps-dev
- cargo build --release
---
kind: signature
hmac: 4b9b8dc348d4d694758245c4964d59fe30af2334028e84f9be75a4e9b9975439
hmac: 8cf10f7d07bef8b089c0f56638dccfaeef3a98e8ca11a27a411a2a8554f4bee0

...
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ uname = "*"
libc = "*"
clap = "*"
yaml-rust = "0.3"
procps-sys = "*"
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern crate error_chain;
extern crate clap;
extern crate uname;
extern crate libc;
extern crate procps_sys;
extern crate yaml_rust;

use std::collections::BTreeMap;
Expand Down Expand Up @@ -39,6 +40,7 @@ use value::Value;
mod mib_sys;
mod mib_disks;
mod mib_net;
mod mib_procs;
mod mib_extend;


Expand Down Expand Up @@ -89,6 +91,10 @@ fn run(matches: clap::ArgMatches) -> Result<()> {
"1.3.6.1.2.1.2.2.1",
"1.3.6.1.2.1.31.1.1.1"
);
mib_procs::get_processes(
&mut values,
"1.3.6.1.2.1.25.4.2.1"
);
mib_extend::get_extend(
&mut values,
&conf,
Expand Down Expand Up @@ -151,7 +157,7 @@ fn respond (
vals.push( (&oid.as_vec()[..], val.as_snmp_value()) );
}

if vals.len() >= 100 {
if vals.len() >= 50 {
break
}
}
Expand Down
33 changes: 33 additions & 0 deletions src/mib_procs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::collections::BTreeMap;
use value::Value;
use oid::OID;
use std::fs;

pub fn get_processes(
values: &mut BTreeMap<OID, Value>,
hr_sw_run_table_oid: &str
) {

if let Ok(entries) = fs::read_dir("/proc") {
for entry in entries {
if let Ok(entry) = entry {
if let Ok(pid) = entry.file_name().into_string().unwrap().parse::<u32>() {
if let Ok(cmdline) = entry.path().join("exe").read_link() {
values.insert(
OID::from_parts_and_instance(&[hr_sw_run_table_oid, "1"], pid),
Value::Integer( pid as i64 )
);
values.insert(
OID::from_parts_and_instance(&[hr_sw_run_table_oid, "2"], pid as u32),
Value::OctetString(String::from(cmdline.file_name().unwrap().to_str().unwrap()))
);
values.insert(
OID::from_parts_and_instance(&[hr_sw_run_table_oid, "4"], pid as u32),
Value::OctetString(String::from(cmdline.to_str().unwrap()))
);
}
}
}
}
}
}