remote script execution

Post support questions that directly relate to Linux/Unix operating systems.

Moderators: Developers, Moderators

Post Reply
obie1
Posts: 4
Joined: Fri Mar 18, 2005 11:00 am

remote script execution

Post by obie1 »

Im running cacti on debian and i need to remotely exceute scripts to a HP-UX host to grab a number from a log file. Nagios has NRPE, is there any way to do this with cacti? Do you thing i can integrate NRPE into some of the custom data querys?


Thanks,
John
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Post by rony »

You can use NRPE, but you can also use SSH in a public/private key setup. Or you can even use rsh, but ssh is prefered.
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
obie1
Posts: 4
Joined: Fri Mar 18, 2005 11:00 am

Post by obie1 »

im not a huge scripter (but i will be :). Can you give me a quick flow on how that would work? Ill prob stick with NRPE since those plugins are already written for my HP-UX system. I just have to modify the output of the NRPE to only send one variable/integer?
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Post by rony »

Post the output from your NRPE command and I will give you and example script to work off of.
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
obie1
Posts: 4
Joined: Fri Mar 18, 2005 11:00 am

Post by obie1 »

[root@usohcol2net001 libexec]# ./check_nrpe -H 10.250.2.10 -c check_load
load average: 0.08, 0.04, 0.03


./check_nrpe -H 10.250.2.10 -c check_disk2
DISK OK - [3075994 kB (68%) free on /dev/vg00/lvol8]


Those are the 2 nrpe plugins i have working now, many more to write. I'll understand it better once i have one of these being graphed.

Thanks!!
User avatar
rony
Developer/Forum Admin
Posts: 6022
Joined: Mon Nov 17, 2003 6:35 pm
Location: Michigan, USA
Contact:

Post by rony »

Let's use perl... I like perl for this stuff... ;)

Code: Select all

#!/usr/bin/perl

# Read stdin and do a regex match for the loads
if (<> =~ m/load average:\s(\d+(\.\d*)?),\s+(\d+(\.\d*)?),\s+(\d+(\.\d*)?)/) {
  # regex match, output parsed values
  print "5min:" . $1 . " 10min:" . $2 . " 15min:" . $3 . "\n";
  exit 0;
} else {
  # no match, output unknown
  print "5min:U 10min:U 15min:U\n";
  exit 1;
}
Save this script to a file, then to use it do something like the following. Saved script is named load_avg_parse.pl in this example:

Code: Select all

./check_nrpe -H 10.250.2.10 -c check_load | ./load_avg_parse.pl
This will output something cacti can use.

Code: Select all

5min:0.08 10min:0.04 15min:0.03


Now for the disk usage one, use the following script to parse the output of the NRPE command:

Code: Select all

#!/usr/bin/perl

# Read stdin and do a regex match for the loads
if (<> =~ m/DISK\s*OK\s*-\s*\[(\d+)\s+[A-Za-z]+\s+\((\d+)\%\)/) {
  # regex match, output parsed values
  print "free_kb:" . $1 . " free_percent:" . $2 . "\n";
  exit 0;
} else {
  # no match, output unknown
  print "free_kb:U free_percent:U\n";
  exit 1;
}
The output will look like:

Code: Select all

free_kb:3075994 free_percent:68
Now, these scripts are just something I whipped up off the top of my head. If the output doesn't match, it will return unknown values, which will show up on the graphs as "NaN".

As for adding the data sources for this, use the others as explains. Pay attention to the Unix Disk Space one, good examples there.

Gluck!
[size=117][i][b]Tony Roman[/b][/i][/size]
[size=84][i]Experience is what causes a person to make new mistakes instead of old ones.[/i][/size]
[size=84][i]There are only 3 way to complete a project: Good, Fast or Cheap, pick two.[/i][/size]
[size=84][i]With age comes wisdom, what you choose to do with it determines whether or not you are wise.[/i][/size]
obie1
Posts: 4
Joined: Fri Mar 18, 2005 11:00 am

Post by obie1 »

Thanks alot, much clearer now!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests