Thursday, May 1, 2008

Nagios with NSClient++ Character Flaws

Arg. It can be frustrating to pass special characters to check_nt arguments!

First, the dreaded ampersand (&):

Unfortunately, it appears as though the ampersand is the field delimiter used by NSClient++, so passing an ampersand to check_nt is absolutely not going to work. Take a look at the following code snippit from check_nt.c :


  249  case CHECK_PROCSTATE:
250
251 if (value_list==NULL)
252 output_message = strdup (_("No service/process specified"));
253 else {
254 preparelist(value_list); /* replace , between services with & to send the request */
255 asprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6,
256 (show_all==TRUE) ? "ShowAll" : "ShowFail",value_list);
257 fetch_data (server_address, server_port, send_buffer);
258 return_code=atoi(strtok(recv_buffer,"&"));
259 temp_string=strtok(NULL,"&");
260 output_message = strdup (temp_string);
261 }
262 break
  620 void preparelist(char *string) {
621 /* Replace all , with & which is the delimiter for the request */
622 int i;
623
624 for (i = 0; (size_t)i < strlen(string); i++)
625 if (string[i] == ',') {
626 string[i]='&';
627 }
628 }


As you can see, the ampersand is hardwired into the request to the NSClient++ server, so any fix will require changes to both the check_nt plugin and NSClient++.

There is no workaround for this, except to avoid using the ampersand (escaping the ampersand with a backslash ( \ ) does not work). If, for example, you are trying to check on the status of the "Backup Exec Device & Media Service", use the service name instead of the display name -- NSClient++ can use either. In this case, the service name is "BackupExecDeviceMediaService", which you can find in the service properties.

P.S. - if you're unfortunate enough to be using Backup Exec, I feel for you.

Next, the dollar sign ($):


The dollar sign is a goofy one too, and can't be escaped with the backslash character ( \ ). Instead, you have to double it and put quotes around it (like so: "$$"). Neat, eh?

An example: let's say that you're trying to monitor the service MSSQL$BKUPEXEC. Unfortunately, this is both the display name, and the service name, so the last trick we used won't work. No worries, though, thanks to our friend the double-dollar-sign-enclosed-in-quotes. Your check_command will look like this:

check_command check_nt!SERVICESTATE!-l "MSSQL"$$"BKUPEXEC"

So awesome! Yay for annoying things!

Note: you might think you're clever and use single quotes instead of double around the entire service name. Unfortunately, that does not work reliably. It does seem to work, however, if you're only checking on one service name in the command. Anyhow, don't bother.

Next up, the backslash ( \ ):

This one is pretty easy, you just double it up ( like so: \\ ). Thus checking on a performance counter will look something like this:


check_command check_nt!COUNTER!-l "\\Network Interface(Intel[R] 82546EB Based Dual Port Network Connection - Packet Scheduler Miniport)\\Bytes Total/sec"

Phew, that counter name is a mouthfull, which is actually why I chose it. Don't try to manually type in your performance counters; copy and paste them. From a terminal to the Windows machine you're monitoring, open up Performance Monitor. Add the counter you're looking for to the graph, select the counter from the legend at the bottom of the window, and then click on the Copy Properties button (it's one of the buttons at the top of the graph). Now open up notepad or your favorite text editor and paste the performance counter data into it. Somewhere in there you should see a .path attribute that contains the entire counter reference which you can copy and paste into the specific Nagios configuration file we're working with (remove the server name and double all of the back slashes). Thankfully we can copy and paste from a terminal in Windows to local windows, if we're running Windows.

Note: I believe that much of the confusion over passing arguments to the check_nt command in Nagios has to do with this double back slash which looks like we're escaping the back slash. We're not...well, not really. Don't expect to simply use regular Bash shell notation in your arguments. Single quotes don't necessarily behave the way you'd like. Escaping doesn't work the way you might expect it to. Just don't bother trying to out-think the system, follow its conventions, make no assumptions, and you'll be fine.

55 comments:

Patrick said...

Excellent! Thank you so much. I tried everything, escaping with \, single quotes, double quotes... never would have thought of the ol' double-double, though perhaps I should have suspected when

'MSSQL$INSTANCE' became
MSSQL$INSTANCE$

in the nagios service detail. LOL.

Cheers!

Rx said...

Just to remark, that if dollar signs are in the name of counter, then correct syntax in Nagios config will be:
check_nrpe -H $HOSTADDRESS$ -c CheckCounter -a "\\MSSQL\
$$SQL_2005:Databases(_Total)\\Data File(s) Size (KB)"
AS far as I understand, backslash escapes for NSClient and second $ is for Nagios parser.

Joe said...

THANK YOU! I have been fighting with the $ issue trying to monitor SQL instances and woul have never thought to put the quotes around just the $$.

Mauro Nunes said...
This comment has been removed by the author.
Mauro Nunes said...

Thanks a LOT!!

It worked for me when using:

check_nt!SERVICESTATE!-l SQLAgent"$$"BKUPEXEC

Anonymous said...

Can anyone recommend the robust IT automation system for a small IT service company like mine? Does anyone use Kaseya.com or GFI.com? How do they compare to these guys I found recently: N-able N-central software remote access
? What is your best take in cost vs performance among those three? I need a good advice please... Thanks in advance!

Anonymous said...

I inclination not acquiesce in on it. I over polite post. Specially the designation attracted me to read the whole story.

Anonymous said...

Genial post and this post helped me alot in my college assignement. Gratefulness you as your information.

Anonymous said...

Hi,

When ever I surf on web I come to this website[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url]Plenty of useful information on sadsoftware.blogspot.com. I am sure due to busy scedules we really do not get time to care about our health. Here is a fact for you. Research points that nearly 80% of all USA grownups are either fat or weighty[url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips].[/url] Hence if you're one of these citizens, you're not alone. In fact, most of us need to lose a few pounds once in a while to get sexy and perfect six pack abs. Now the question is how you are planning to have quick weight loss? [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss[/url] is really not as tough as you think. Some improvement in of daily activity can help us in losing weight quickly.

About me: I am blogger of [url=http://www.weightrapidloss.com/lose-10-pounds-in-2-weeks-quick-weight-loss-tips]Quick weight loss tips[/url]. I am also health expert who can help you lose weight quickly. If you do not want to go under difficult training program than you may also try [url=http://www.weightrapidloss.com/acai-berry-for-quick-weight-loss]Acai Berry[/url] or [url=http://www.weightrapidloss.com/colon-cleanse-for-weight-loss]Colon Cleansing[/url] for effortless weight loss.

Term Papers said...

I have been visiting various blogs for my term papers writing research. I have found your blog to be quite useful. Keep updating your blog with valuable information... Regards

Anonymous said...

Странно, искал совсем не это, гугл выдал Ваш сайт, и судя по всему не зря, есть что почитать! Goodwork!

eco travel agency costa rica said...

Hi buddy, firstly I would like to send greetings to all readers then I think that this information is amazing and very entertainment information, I was looking information about Nagios with NSClient++ Character Flaws , and this information is very professional and I would like to have any update about, thanks for sharing!!

Anonymous said...

The article was very interesting and informative for me. weight loss Read a useful article about tramadol tramadol

Anonymous said...

Thanks a lot!!!
You saved me :)
Matthew

Anonymous said...

sell [URL=http://jacket-dresses.net/]moncler sale[/URL] for less QVRhnHsJ [URL=http://jacket-dresses.net/ ] http://jacket-dresses.net/ [/URL]

Anonymous said...

get cheap [URL=http://jacket-dresses.net/]moncler jackets sale[/URL] suprisely PwWkoGng [URL=http://jacket-dresses.net/ ] http://jacket-dresses.net/ [/URL]

Anonymous said...

Hiya very nice website!! Man .. Beautiful .. Amazing .

. I'll bookmark your blog and take the feeds also? I am glad to find a lot of helpful info here within the put up, we want work out more strategies on this regard, thanks for sharing. . . . . .
My blog ... Twin Cities Auto Glass

Anonymous said...

Nice post. I learn something totally new and challenging on sites I stumbleupon everyday.
It will always be useful to read through content from other authors and practice a little something from other sites.
Feel free to surf my web-site Buy Viarex

Anonymous said...

I am sure you will love CFeJRaFm [URL=http://www.louis--vuitton--online--shop.org/]louis vuitton shoes online[/URL] for less gHpPnSXd [URL=http://www.louis--vuitton--online--shop.org/ ] http://www.louis--vuitton--online--shop.org/ [/URL]

Anonymous said...

DifAnn [url=http://onnrainnmcm.com/#79757]MCM 韓国[/url] BphQhb http://onnrainnmcm.com/ OqwPyr [url=http://mcmsenmon.com/#00892]MCM[/url] ZggUyu http://mcmsenmon.com/ GsgYzg [url=http://ninnkimcm.com/#96165]MCM[/url] LmyEnn http://ninnkimcm.com/ DcnBfj [url=http://kaidokumcm.com/#78657]MCM 韓国[/url] HyhPbm http://kaidokumcm.com/ CucCds [url=http://manzokumcm.com/#02006]MCM 長財布[/url] JmlXqd http://manzokumcm.com/ XyuMcz http://chloenihon.com/ PwuKhu [url=http://chloenihon.com/]クロエ ネックレス[/url] JihArz http://louboutindendou.com/ OkfMtj [url=http://louboutindendou.com/]クリスチャンルブタン 財布[/url] OpbXvi http://guccisenmon.com/ PpkWuu [url=http://guccisenmon.com/]グッチ キーケース[/url] TvuFnb [url=http://mcmhannbai.com/]mcm3806[/url] WgsDhz [url=http://mcmhannbai.com/]MCM リュック[/url]

Anonymous said...

cheap [URL=http://burberry-outlet.zoomshare.com/]burberry for men[/URL] to take huge discount cCzZmvnv [URL=http://burberry-outlet.zoomshare.com/ ] http://burberry-outlet.zoomshare.com/ [/URL]

Anonymous said...

Brokersring.com - Learn how to turn $500 into $5,000 in a month!

[url=http://www.brokersring.com/]Make Money Online[/url] - The Secret Reveled with Binary Option

Binary Options is the way to [url=http://www.brokersring.com/]make money[/url] securely online

Anonymous said...

Thank you a lot for sharing this with all people you actually know what you are speaking approximately!
Bookmarked. Please additionally discuss with my web site =).

We can have a hyperlink exchange contract among us

Also visit my web-site - fake louis vuitton handbags
My web site - fake louis vuitton handbags

Anonymous said...

cheap nike air max 90 sxyudfls cheap nike air max kosrrbik nike air max 1 ehxptfkw nike air max 90 zraiqdjv nike air max 95 govzsfvb nike air max wvoilsxe nike free run fjlgrvgn nike store uk oalvfici nike uk zoniskcl

Anonymous said...

cheap ugg boots yupcbpmh cheap uggs vszfwbyf ugg boots sale ozhuctwy ugg boots uk wuwhtvco ugg boots qdzvmzjd ugg sale xinbnvsc

Anonymous said...

I have been browsing on-line more than 3 hours today, yet I never found
any attention-grabbing article like yours. It's pretty value enough for me. In my view, if all website owners and bloggers made good content as you probably did, the internet might be a lot more useful than ever before.

My page; www.coachhandbagsoutletshop2013.com

Anonymous said...

Right here is the perfect web site for everyone who really
wants to find out about this topic. You know so much its almost hard
to argue with you (not that I personally will need to…HaHa).
You definitely put a fresh spin on a subject that's been written about for decades. Wonderful stuff, just great!

Here is my blog post ... ミュウミュウ

Anonymous said...

Excellent weblog here! Also your site rather a lot up very fast!
What web host are you the use of? Can I get your associate hyperlink for your
host? I desire my web site loaded up as quickly as yours lol

My website: コーチ長財布

Anonymous said...

I am in fact grateful to the holder of this web site who has shared this wonderful
article at at this time.

My blog :: トリーバーチ財布

Anonymous said...

Heya! I just wanted to ask if you ever have any problems
with hackers? My last blog (wordpress) was hacked
and I ended up losing many months of hard work due
to no back up. Do you have any solutions to protect against hackers?


Stop by my web page miu miu 財布

Anonymous said...

I was curious if you ever thought of changing the page layout of your website?
Its very well written; I love what youve got to say.
But maybe you could a little more in the way of content so people could connect with it better.
Youve got an awful lot of text for only having 1 or 2 images.
Maybe you could space it out better?

My webpage: ミュウミュウ新作

Anonymous said...

Highly energetic article, I liked that bit. Will there be a part 2?


My website ... toryburchoutletshopx.com

Anonymous said...

For newest information you have to visit world-wide-web and on internet
I found this site as a finest site for most recent updates.


Also visit my page; クロエ ハンドバッグ

Anonymous said...

Hi to every one, it's genuinely a pleasant for me to pay a visit this web page, it contains valuable Information.

my weblog - クロエ店舗

Anonymous said...

Wow, superb blog format! How lengthy have you been blogging for?
you made blogging look easy. The full glance of your web site is fantastic, as smartly as the content!


My page - chloe バッグ

Anonymous said...

I'm really inspired with your writing skills and also with the layout for your blog. Is that this a paid topic or did you modify it yourself? Either way keep up the nice quality writing, it is rare to see a great weblog like this one nowadays..

Also visit my web-site ... トリーバーチ財布

Anonymous said...

It is appropriate time to make some plans for the future and it is time to be happy.

I have read this post and if I could I desire to suggest you few interesting things or suggestions.
Perhaps you can write next articles referring to
this article. I desire to read more things about it!


Here is my blog post; Acai Ultra Lean

Anonymous said...

Hi, i think that i saw you visited my blog thus i came to “return the
favor”.I am attempting to find things to improve my web site!
I suppose its ok to use some of your ideas!
!

my blog post: loveuapple.com

Anonymous said...

It's remarkable designed for me to have a web site, which is helpful in support of my experience. thanks admin

my web-site www.19luglio1992.org

Anonymous said...

Pretty nice post. I just stumbled upon your weblog and wanted to say that I've truly enjoyed browsing your blog posts. After all I will be subscribing to your feed and I hope you write again very soon!

My website :: www.old-yacht.berozy.com

Anonymous said...

Mr Bernanke is the one with the pottery. Click Here to visit VCW VicMan's stickers in bulk Editor include rotating the stickers in bulk, considering they'll be
marked at $15 for a pack of cigarettes, front and back,
and whether or not to consume GMO foods.

Also visit my webpage ... Vinyl sticker

Anonymous said...

Have you ever considered writing an ebook or guest authoring on
other sites? I have a blog based upon on the same topics you discuss and would
really like to have you share some stories/information.

I know my subscribers would value your work. If you're even remotely interested, feel free to send me an email.

Review my web-site; クリスチャンルブタン

Anonymous said...

Hello my family member! I wish to say that this article is awesome, great
written and come with approximately all significant infos.
I would like to see more posts like this .

Here is my web page コーチ アウトレット

Anonymous said...

I'm not sure exactly why but this site is loading incredibly slow for me. Is anyone else having this issue or is it a problem on my end? I'll check back later on and see
if the problem still exists.

Look at my webpage: プラダバッグ

Anonymous said...

Wow, marvelous weblog format! How lengthy have you ever been
blogging for? you make running a blog glance easy.
The whole look of your site is excellent, let alone the content material!


My blog post :: ロレックススーパーコピー

Anonymous said...

This is a topic which is close to my heart... Cheers! Exactly where are your contact details though?


My homepage ... アバクロ

Anonymous said...

Fantastic End-of-the-year Merchandise For Educators

Feel free to surf to my site Epson Powerlite Home Cinema 5020UBe review
()

Anonymous said...

Greetings! I've been following your weblog for a long time now and finally got the bravery to go ahead and give you a shout out from Dallas Tx! Just wanted to say keep up the excellent job!

Also visit my site - forex trading charts ()

Anonymous said...

What's up to all, how is everything, I think every one is getting more from this web site, and your views are nice in support of new visitors.

Feel free to surf to my weblog; free binary options system

Anonymous said...

Simply desire to say your article is as astonishing.
The clarity in your post is just great and i could assume you are an expert on this subject.
Well with your permission let me to grab your feed to keep up to date with forthcoming post.
Thanks a million and please continue the rewarding work.



Also visit my website :: cedarfinanc

Anonymous said...

However, it is also because of this negative thinking which is the primary
cause of their weihgt problem. Then the skinny guy
finds weight gainers and tries them, or some other worthless supplement, and never really understands why he is not big and muscular like the other guys at the gym.
How to gain weight for skinny guys is about attitude, exercise,
nutrition, and rest.

Also visit my webpage :: how to gain weight with a fast metabolism ()

Anonymous said...

Antenna Tower- No cost Interrelated Roadmap Related to Antenna

Also visit my web-site casinoeuro

Anonymous said...

Details about Lumisource Home entertainment system Chair Producer

Here is my webpage ... converter video to mp3 online

Melisa Marzett said...

Many thanks for this detailed article! I am always asking myself why use a excise dissertation writing overhaul? While ​http://dissertationwriting.services/ exist! I still don't understand!

Anonymous said...

This was helpful. Thank you. I was struggling with parentheses. Quotes around them worked.

-d SHOWALL -l "Perceptive Content Email Agent "("Primary")""

'behold what manner of men are these, who struggle to quote parentheses'
--Sarsipius Bartholomew AD 82