HP Deskjet F4480 - Cups, Saned, and Samba oh my!
Part #1 Cups install/configuration
So, my old HP Deskjet all-in-one finally gave up the ghost earlier this year. Something to do with the Printer Cartridges and error’s all over the place. Well, as a family of 4 1/2(does the dog count as a half?) we really needed a new printer/scanner/copier combo, but I just couldn't justify the $100+ for a networked all-in-one with limited functionality. So alas! out comes the penguin in me. We bought a HP Deskjet F4480 All-In-One from walmart last weekend, and I set out to network share the device.
Here were my goals:
* Get Cups to share the printer to all the machines in the house
*Enable remote administration of CUPS so that I wouldn’t have to VNC to the server and administer everything
*Get the Scanner to work with saned and sanetwain (window’s Xsane equivalent) so that we can scan from the windows machine’s, along with the linux machines.
*Auto-push window’s print drivers to window’s machines so I’m not hunting down the silly CD every time I need to add a printer for guests that come in and want to print
*Secure things down so only our local subnet can print/scan/take over the world.
* Do all of this from a headless virtualbox interface
Did I accomplish my goals? yup, all but the last one. Everything worked splendid in Virtualbox during my testing phases (I test all of my new home ‘servers’ in virtualbox before pushing them out). But when I pushed it prod to my little server (AMD 1.2Ghz w/ only 1GB ram, 40GB hd, I’m a cheap bastard), my little server couldn’t keep up with all of the USB emulation between the device, server and virtualbox..CPU was at 90%+ and memory went through the roof when attempting to print. So I took it out of virtualbox until I can scrounge up enough dough to buy a decent server. (This server hosts: pop3, cups, gallery2 (our family photo gallery), vpn, nagios, and other such services through VirtualBox...so I REALLY need an upgrade at some point).
I’ll post how I did all of this, from memory (although I might miss a dependency or two).
Step 1: Download files and install services
I did all of this from my Ubuntu 10.04LTS server, so mileage may vary. First, I went to HP’s opensource website: http://hplipopensource.com/hplip-web/index.html and downloaded the .deb package (newer than what Ubuntu has in it’s repo, and fixes issues with the scanner btw). Then off to cups.org to download windows driver support (http://www.cups.org/software.php). Now time for packages and dependencies!
Checking my list of installed packages, I must assume that I installed the following (and dependencies of course):
DO FIRST: dpkg -i yourhplip-package.dpkg and install it’s called for dependencies!
CUPS: cups, cups-bsd, cups-client, cups-common, cups-pdf, cups-ppdc (for ppd manipulation), ghostscript-cups, hal-cups-utils, libcups2, libcups2-dev, libgnomecups1.0-1
SANE: sane, libsane, libsane-dev, sane-utils, xsane, xsane-common
SAMBA: samba, samba-common, samba-common-bin, system-config-samba (gui, came default for some reason)
Okay, so once the packages were installed, I set out to get cups installed and configured so that I could at least print over the network.
I’m not going to go into detail about each configuration change and what I did (although I’ll add some comments here and there in the configuration). So here is what my /etc/cups/cupsd.conf looks like (make sure you backup your config before making changes). Keep in mind, the policies were created by ubuntu when I installed the package, for now I left them alone until I can create my own policies, but it works so I’m not complaining right now.
## Go here for my cupds.conf. It appears blogger seems to think my configuration is in html and attempts to format it, oi.
http://pastebin.ca/1944437
Okay, save config and restart cups! /etc/init.d/cups restart (or if your using upstart.. restart cups).
Since I’m a CLI lover, all of this was done from an ssh session, once cups is restarted, you should be able to navigate to the cups page from anyone in (in this example 192.168.1.*) subnet. Fire up firefox (you ARE using firefox, right?) and navigate to: https://your.cups.ip:631 I say https, because by default cups wants https authentication, and you might as well get into the habit of using https for security purposes.
I hope you followed the first instruction to install the hplip driver before you started installing/configuring cups..if not, you should be able to install the .deb package for hplip before configuring your printer. Restart cups after installing hplip just in case.
Now, it’s time to install the printer! Administration - > Printers -> Add Printer ->Local Printer
In my case, it shows up as: HP Deskjet F4400 series (HP Deskjet F4400 series). Select it and click next. Give it a name, description, location and click ‘share printer’, click continue. Select your driver, if it’s not listed..search your server for the *.ppd file for your printer (this is what I had to do for the hp4480), unzip the ppd file, and copy it over to the machine that you are browsing cups from, then add the .ppd file). Once this is done, click ‘Add Printer’.
Tada! Now you have a shared network printer with cups.
From a linux client, you can add the printer via the ipp address (In cups, click ‘printers’ and click the printer..up in the address bar, copy the url, and paste for ipp printing). For windows client’s, if you have ipp setup in windows (more on that in part 2/3) you can do the following (example is with Windows 7)
Start -> Devices and Printers -> Add Printer -> Add network printer ->The Printer I want isn’t listed -> Select a shared printer by name ->Copy/Paste the URL as above into this and click next.
For some people this may work (surf the net for ‘IPP printing in Windows 7’ to find out how you enable ipp printing in windows 7...can’t remember this off the top of my head). For me, and for whatever reason this didn’t work very well. So I opted to use samba in order to push windows drivers out to my connected clients. More on this in the next part.
Part 2 will cover Samba/Sane configurations with Cups for sharing your scanner and pushing out windows drivers.
Sunday, September 19, 2010
Wednesday, June 2, 2010
Filter External Email with Gmail
BIS Filtering Functionality with Android Mobile
So, recently I saw the light and picked up a HTC Hero running Android 2.1. I love the thing, but I did run into one issue with it; work email. Before I ditched my Blackberry, I was able to use the BIS (Blackberry Internet Service) Portal to filter my work email, thus receiving only specific messages (such as nagios alerts, important email from co-workers, etc). As I receive on average 600+ messages a day, this was a very critical feature. But when I went to the Android, I noticed that this feature was lacking. On the first night with my fancy new phone and all of my work email being sent to it, I thought the girlfriend was going to find an orifice of mine to place said phone due to it going off every few minutes and waking her up. Well, there had to be a better solution than this, and there is! While surfing around the internet for a possible solution, I came across a blog post of a guy who filtered his G-Mail account for specific emails; I just took it a step further.
What I did was use Gmail's 'Add POP3 Email account' feature to check my work email, then filter based on specific subjects/from/etc. Anything that did not match the filter criteria was automatically deleted without going to the Inbox first. This actually works pretty well, every so often an email will slip through the filter; but that's expected for the amount of email I receive on a daily basis. This not only works for Android type phones, but just about any phone that can receive gmail via the pop3 setting (I'll be testing this on a Palm here shortly). Thus mimicking the handy BIS filtering, and saving your phone from being launched in the air by a significant other who woke up to the message notification for the umpteenth time.
First things first, make sure you have a Gmail account. Yes, this sounds silly that I would mention it...but you never know. Everything else follows in quick steps, so follow along.
1. Log into Google mail
2. Select 'Settings' in Upper right-hand corner of the screen
3. Select ' Accounts and Import' Tab
4. Under 'Check mail using POP3' click the 'Add POP3 email account', a popup box will come up (make SURE you have enabled popups on your browser prior to doing this)
5. Enter the foreign email address (such as: user@somecompany.com and click 'next step'
6. Enter username, password, POP Server, port #, Label incoming messages. Label incoming messages is optional, but it's nice to see where the email came from. In this case, I labeled all incoming messages 'Work'. So when I receive an email on my phone, I can see if it came from work or into my regular gmail account. (VALUABLE STEP: click 'leave mail on server', if you don't; you won't be getting your regular email from user@somecompany.com with whatever MTA that you use)
7. Click 'Add Account'
8. Either select 'Yes, I want to be able to send mail as user@somecompany.com, or No. (for just receiving email, I used the No option, but that's up to you)
9. Click 'Next Step'
10. After your last step, google will go out and fetch your pop3 email from user@somecompany.com, if this is successful than continue on. If it is not successful, make sure your settings for your pop3 account is configured properly (including your password)
Set Filters
Now that you are receiving your user@somecompany.com email, it's time to filter out specific emails that you want to receive on your phone.
1. Click 'Filters' Tab inside of Settings
2. click 'Create New Filter'
3. To: = user@somecompany.com
4. Add: - next to anything you want filtered into your in-box, separated by a comma.
ex: -nagios@somecompany.com,-myboss@somecompany.com
5. Click 'Test Search'. Your excluded filter options should not show up on your search results, which is a good thing; you shouldn't see your filtered objects.
6. Click 'Next Step'
7. Select your option on where to put the un-filtered email. In this case I chose to delete instead of Archive my email.
If you archive your non-filtered email, it can still be read, but won't be going into your google inbox.
8. Click on 'Also apply filter to xxx conversations below'
9. Click 'Create Filter'
What this feature does is the following:
1. Google checks user@somecompany.com's email
2. E-mail is put through the filter that you setup. If from/subject/body/etc matches your - (do not include) filter, than it is delivered into your Gmail
account with the label that you attached to it in the previous steps.
3. If it does not match your (do not include) filter, than the email is automatically deleted (or archived, however you set this up)
There you have it! BIS functionality with Gmail and the android! As I said earlier, based upon the amount of email that you receive, some email's might squeeze by.
But I'll take an extra email or two over 600 of them going to my device.
So, recently I saw the light and picked up a HTC Hero running Android 2.1. I love the thing, but I did run into one issue with it; work email. Before I ditched my Blackberry, I was able to use the BIS (Blackberry Internet Service) Portal to filter my work email, thus receiving only specific messages (such as nagios alerts, important email from co-workers, etc). As I receive on average 600+ messages a day, this was a very critical feature. But when I went to the Android, I noticed that this feature was lacking. On the first night with my fancy new phone and all of my work email being sent to it, I thought the girlfriend was going to find an orifice of mine to place said phone due to it going off every few minutes and waking her up. Well, there had to be a better solution than this, and there is! While surfing around the internet for a possible solution, I came across a blog post of a guy who filtered his G-Mail account for specific emails; I just took it a step further.
What I did was use Gmail's 'Add POP3 Email account' feature to check my work email, then filter based on specific subjects/from/etc. Anything that did not match the filter criteria was automatically deleted without going to the Inbox first. This actually works pretty well, every so often an email will slip through the filter; but that's expected for the amount of email I receive on a daily basis. This not only works for Android type phones, but just about any phone that can receive gmail via the pop3 setting (I'll be testing this on a Palm here shortly). Thus mimicking the handy BIS filtering, and saving your phone from being launched in the air by a significant other who woke up to the message notification for the umpteenth time.
First things first, make sure you have a Gmail account. Yes, this sounds silly that I would mention it...but you never know. Everything else follows in quick steps, so follow along.
1. Log into Google mail
2. Select 'Settings' in Upper right-hand corner of the screen
3. Select ' Accounts and Import' Tab
4. Under 'Check mail using POP3' click the 'Add POP3 email account', a popup box will come up (make SURE you have enabled popups on your browser prior to doing this)
5. Enter the foreign email address (such as: user@somecompany.com and click 'next step'
6. Enter username, password, POP Server, port #, Label incoming messages. Label incoming messages is optional, but it's nice to see where the email came from. In this case, I labeled all incoming messages 'Work'. So when I receive an email on my phone, I can see if it came from work or into my regular gmail account. (VALUABLE STEP: click 'leave mail on server', if you don't; you won't be getting your regular email from user@somecompany.com with whatever MTA that you use)
7. Click 'Add Account'
8. Either select 'Yes, I want to be able to send mail as user@somecompany.com, or No. (for just receiving email, I used the No option, but that's up to you)
9. Click 'Next Step'
10. After your last step, google will go out and fetch your pop3 email from user@somecompany.com, if this is successful than continue on. If it is not successful, make sure your settings for your pop3 account is configured properly (including your password)
Set Filters
Now that you are receiving your user@somecompany.com email, it's time to filter out specific emails that you want to receive on your phone.
1. Click 'Filters' Tab inside of Settings
2. click 'Create New Filter'
3. To: = user@somecompany.com
4. Add: - next to anything you want filtered into your in-box, separated by a comma.
ex: -nagios@somecompany.com,-myboss@somecompany.com
5. Click 'Test Search'. Your excluded filter options should not show up on your search results, which is a good thing; you shouldn't see your filtered objects.
6. Click 'Next Step'
7. Select your option on where to put the un-filtered email. In this case I chose to delete instead of Archive my email.
If you archive your non-filtered email, it can still be read, but won't be going into your google inbox.
8. Click on 'Also apply filter to xxx conversations below'
9. Click 'Create Filter'
What this feature does is the following:
1. Google checks user@somecompany.com's email
2. E-mail is put through the filter that you setup. If from/subject/body/etc matches your - (do not include) filter, than it is delivered into your Gmail
account with the label that you attached to it in the previous steps.
3. If it does not match your (do not include) filter, than the email is automatically deleted (or archived, however you set this up)
There you have it! BIS functionality with Gmail and the android! As I said earlier, based upon the amount of email that you receive, some email's might squeeze by.
But I'll take an extra email or two over 600 of them going to my device.
Wednesday, November 4, 2009
Custom Error reporting email in bacula
So the other day, I was tasked with creating a custom email alert for a select number of bacula clients that failed to back up. Out of 150 clients backing up, 10 of them were extremely important. So instead of admin's having to sift through the failed client backups of laptops that were not plugged in that day, I created a custom mysql query against the bacula server.
First thing I did was create a tab delimited file called clients.txt inside of my custom scripts folder (/etc/bacula/scripts). Inside of the clients.txt file is the following:
clientname-fd Joe Blow
clientname2-fd Jane Doe
clientname3-fd John Doe
Note that the clientname and the username HAS to be seperated by a TAB. If you put a space in after -fd and then tabbed, the script will not work.
Next, create a new script called bacula-query.sh (make it executable) in the /etc/bacula/scripts/ directory and paste the following into it (remove the line numbers, as I will be using line #'s to describe what the script does):
bacula-query.sh
1. #!/bin/bash
2. while IFS=$'\t' read -r clients name; do
3. echo $name
4. mysql -u bacula bacula -t -B -e "SELECT DISTINCT Job.JobId,Client.Name as Client,Level,StartTime,JobFiles,JobBytes,Job.JobStatus as Status FROM Client,Job,JobMedia,Media WHERE Client.Name='${clients}' AND Client.ClientId=Job.ClientId AND JobMedia.JobId=Job.JobId AND JobMedia.MediaId=Media.MediaId AND Job.StartTime >= (CURDATE()) ORDER BY Job.StartTime;"
5. echo "T=Success E=Error R=Running t=waiting on start time"
6. echo -e \\n
7. done < /etc/bacula/scripts/clients.txt | mailx -s "Bacula Backup WATCH list" admin-acct@yourcompany.com
Line Details:
1. Call Bash
2. run a while statement against the tab delimited file called clients.txt, column 1 is clients, column 2 is name.
3. echo the name of the person
4. run a mysql query against the job id, client name, start time, bytes, search for backups of the current day
5. echo the codes for: success, error, running and waiting
6. echo a blank line
7. end the while statement, read clients.txt and send an email with the subject of Bacula Backup WATCH list to an email address.
The output (email) looks like this:
Joe Blow T=Success E=Error R=Running t=waiting on start time
Jane Doe
+-------+----------------+-------+---------------------+----------+------------+--------+
| JobId | Client | Level | StartTime | JobFiles | JobBytes | Status | +-------+----------------+-------+---------------------+----------+------------+--------+
| 6908 | clientname2-fd | I | 2009-11-03 17:17:23 | 625 | 6138170925 | T | +-------+----------------+-------+---------------------+----------+------------+--------+ T=Success E=Error R=Running t=waiting on start time
(**NOTE** Blogger cuts off part of the line on the above output...running this will actually output the table into a cleaner format than blogger formatted this)
As you can see, the first client (Joe Blow) has no data, thus did not backup. the 2nd client (Jane Doe) successfully backed up and output of the backup is shown in the email.
From there, I created a cronjob that calls the script every night mon-fri at 10pm (when client backups should be done)
0 22 * * 1,2,3,4,5 /etc/bacula/scripts/bacula-query.sh #Email Bacula WATCH list
There you go, automated emails on specific backups of clients as a WATCH list of important clients.
First thing I did was create a tab delimited file called clients.txt inside of my custom scripts folder (/etc/bacula/scripts). Inside of the clients.txt file is the following:
clientname-fd Joe Blow
clientname2-fd Jane Doe
clientname3-fd John Doe
Note that the clientname and the username HAS to be seperated by a TAB
Next, create a new script called bacula-query.sh (make it executable) in the /etc/bacula/scripts/ directory and paste the following into it (remove the line numbers, as I will be using line #'s to describe what the script does):
bacula-query.sh
1. #!/bin/bash
2. while IFS=$'\t' read -r clients name; do
3. echo $name
4. mysql -u bacula bacula -t -B -e "SELECT DISTINCT Job.JobId,Client.Name as Client,Level,StartTime,JobFiles,JobBytes,Job.JobStatus as Status FROM Client,Job,JobMedia,Media WHERE Client.Name='${clients}' AND Client.ClientId=Job.ClientId AND JobMedia.JobId=Job.JobId AND JobMedia.MediaId=Media.MediaId AND Job.StartTime >= (CURDATE()) ORDER BY Job.StartTime;"
5. echo "T=Success E=Error R=Running t=waiting on start time"
6. echo -e \\n
7. done < /etc/bacula/scripts/clients.txt | mailx -s "Bacula Backup WATCH list" admin-acct@yourcompany.com
Line Details:
1. Call Bash
2. run a while statement against the tab delimited file called clients.txt, column 1 is clients, column 2 is name.
3. echo the name of the person
4. run a mysql query against the job id, client name, start time, bytes, search for backups of the current day
5. echo the codes for: success, error, running and waiting
6. echo a blank line
7. end the while statement, read clients.txt and send an email with the subject of Bacula Backup WATCH list to an email address.
The output (email) looks like this:
Joe Blow T=Success E=Error R=Running t=waiting on start time
Jane Doe
+-------+----------------+-------+---------------------+----------+------------+--------+
| JobId | Client | Level | StartTime | JobFiles | JobBytes | Status | +-------+----------------+-------+---------------------+----------+------------+--------+
| 6908 | clientname2-fd | I | 2009-11-03 17:17:23 | 625 | 6138170925 | T | +-------+----------------+-------+---------------------+----------+------------+--------+ T=Success E=Error R=Running t=waiting on start time
(**NOTE** Blogger cuts off part of the line on the above output...running this will actually output the table into a cleaner format than blogger formatted this)
As you can see, the first client (Joe Blow) has no data, thus did not backup. the 2nd client (Jane Doe) successfully backed up and output of the backup is shown in the email.
From there, I created a cronjob that calls the script every night mon-fri at 10pm (when client backups should be done)
0 22 * * 1,2,3,4,5 /etc/bacula/scripts/bacula-query.sh #Email Bacula WATCH list
There you go, automated emails on specific backups of clients as a WATCH list of important clients.
Friday, October 23, 2009
Sample WMI scripts
So, I figured I would deviate from the regular linux techie stuff and put up one of the WMI vbscripts that I have been playing with the last few days.
RunningServices.vbs: At work, we use a backup solution that requires VSC (Volume Shadow Copy) running on the client machine in order to backup opened files. When setting up the clients on the individual machines, we usually check to make sure VSC is set to automatic; but sometimes we forget. With 300+ machines, going to each remote client, or connecting to each remote client via services.msc would be WAY too time consuming. So, alas, I whipped up a vbscript that uses WMI to connect to each machine. Keep in mind, I am NOT a vbscript person, I had to rely on my rusty memory from the last few years of dabbling in vbscripting.
'RunningServices.vbs
On Error Resume Next
Dim oShell
Set oShell = CreateObject("Wscript.Shell")
forceUseCScript
Sub forceUseCScript()
If Not WScript.FullName = WScript.Path & "\cscript.exe" Then
oShell.Popup "Launched using wscript. Relaunching...",3,"WSCRIPT"
oShell.Run "cmd.exe /k " & WScript.Path & "\cscript.exe //NOLOGO " & Chr(34) & WScript.scriptFullName & Chr(34),1,False
WScript.Quit 0
End If
End Sub
arrComputers = Array(".")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
WScript.Echo "Computer: " & strComputer
WScript.Echo "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Service WHERE DisplayName = 'Volume Shadow Copy'",,48)
For Each objItem in colItems
Wscript.Echo "Service: " & objItem.DisplayName
Wscript.Echo "StartMode: " & objItem.StartMode
Wscript.Echo "State: " & objItem.State
Next
Next
Executing this will display the output on a terminal window. So there you have it! Now I'm currently experimenting with getting MS Access 2007 Professional to work in Wine! If I can get it to work, I will have to post the results :-)
RunningServices.vbs: At work, we use a backup solution that requires VSC (Volume Shadow Copy) running on the client machine in order to backup opened files. When setting up the clients on the individual machines, we usually check to make sure VSC is set to automatic; but sometimes we forget. With 300+ machines, going to each remote client, or connecting to each remote client via services.msc would be WAY too time consuming. So, alas, I whipped up a vbscript that uses WMI to connect to each machine. Keep in mind, I am NOT a vbscript person, I had to rely on my rusty memory from the last few years of dabbling in vbscripting.
'RunningServices.vbs
'VB Script to check on the status of VSC running on remote machines
'Need to replace the "." next to Array with a remote computer name
'syntax is: "computer1","computer2","etcetcetc"
On Error Resume Next
Dim oShell
Set oShell = CreateObject("Wscript.Shell")
forceUseCScript
Sub forceUseCScript()
If Not WScript.FullName = WScript.Path & "\cscript.exe" Then
oShell.Popup "Launched using wscript. Relaunching...",3,"WSCRIPT"
oShell.Run "cmd.exe /k " & WScript.Path & "\cscript.exe //NOLOGO " & Chr(34) & WScript.scriptFullName & Chr(34),1,False
WScript.Quit 0
End If
End Sub
arrComputers = Array(".")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
WScript.Echo "Computer: " & strComputer
WScript.Echo "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Service WHERE DisplayName = 'Volume Shadow Copy'",,48)
For Each objItem in colItems
Wscript.Echo "Service: " & objItem.DisplayName
Wscript.Echo "StartMode: " & objItem.StartMode
Wscript.Echo "State: " & objItem.State
Next
Next
Executing this will display the output on a terminal window. So there you have it! Now I'm currently experimenting with getting MS Access 2007 Professional to work in Wine! If I can get it to work, I will have to post the results :-)
Friday, September 25, 2009
NTP event-handler in Nagios
Nagios, "Nagios Ain't Gonna Insist On Sainthood"....What an awesome tool for systems administration. I have been using Nagios since the days of netsaint back when it was first released in 1999. In 10 years time, the program has matured and become a de-facto standard in Network and Systems Monitoring. In recent years there have been many spin-off's of nagios, but I have chosen to stick with the core package.
One of the most over-looked, but very powerful, features of Nagios is it's ability to use event handlers (Nagios Docs). An Event Handler allows for a script to be executed based on changes to the service/host system state. There are endless possibilities to using this feature. Usually when Nagios alerts to a changed system state (warning/critical), an administrator is emailed/paged/tweeted in response to the system state change. The said administrator then logs in, restarts services, checks network connection, finds out why disk space went critical, so on and so forth. Event-Handler's can do this and so much more!
I have written numerous event-handler scripts that creates a 'self-healing' environment for different servers utilizing event-handlers and NRPE. Some of the Event handlers that I utilize in Nagios are the following:
*Disk Space Critical - When Nagios alerts to a warning/critical disk space, NRPE executes a custom du-scan.sh script that sorts all of the data on the mount point by highest ammt used, puts it into a log file on the /tmp directory and emails the location of the log to administrators
*CPU Load Critical - When Nagios alerts to a warning/critical CPU Load, whether it's in linux or windows, a script is executed (Bash in linux, VB in windows) that emails administration the top 5 running CPU process's on the server
*NTP (Network Time Protocol) time sync Critical - Sometimes when CPU load goes critical, the NTP service running on a Linux machine goes WAY out of sync (over 1000seconds) causing the NTP Daemon to crash. When the time is off on the server, the various services we use, report different times, causing even more issues. The fix to this, is to have Nagios restart the ntp service on the remote server via NRPE.
This little blog entry will detail how to setup an NTP event-handler for Nagios. You can use this as a base for just about anything else event-handler related.
This is written with the assumption that the person using this is already familiar with, and has a Nagios Server utilizing NRPE for linux clients, along with having nagios-plugins installed on the client. This isn't a basic 'nagios howto' at all.
First things first, setting up and configuring the remote client for allowing command arguments.
1. Navigate to your nrpe source directory (in this case: /root/Download/nrpe2-12/
2. Reconfigure nrpe for command arguments
./configure --enable-command-args && make && make install
3. Modify the nrpe.cfg file
a) change: dont_blame_nrpe=0 to: dont_blame_nrpe=1
b) add the following to your command arguments:
## /usr/local/.... is the path to the check_ntp plugin that comes with nagios plugins, change 0.pool.ntp.org to the ntp server that your organization uses to get ntp data. Warning at 10 seconds, critical at 20 seconds.
command[check_ntp]=/usr/local/nagios/libexec/check_ntp -H 0.pool.ntp.org -w 10 -c 20
## /usr/local/.... is the path to the event-ntp handler, as seen below.
command[event-ntp]=/usr/local/nagios/libexec/event-ntp $ARG1$ $ARG2$ $ARG3$
4. create a file called event-ntp, u:g of nagios:nagios, set executable.
5. Drop this code into the event-ntp file:
#!/bin/bash
## This is an event handler that will be executed on Warnings and Critical alerts.
## On Warnings, an ntp query will be issued, and the email will be sent to the specified admin
## On Critical, an ntp query will be issued, and the ntpd service will be restarted to re-sync the clocks
case "$1" in
OK)
;;
WARNING)
echo -e "Running NTP Query" "\n"
ntpq -p | mailx -s "HOSTNAME - NTP Query" adminacct@example.com
;;
UNKNOWN)
;;
CRITICAL)
case "$2" in
SOFT)
case "$3" in
3)
echo -e "Running NTP Query & Restarting NTP Service" "\n"
ntpq -p | mailx -s "HOSTNAME - NTP Query - Restarted NTPD" adminacct@example.com && /usr/bin/sudo /sbin/service ntpd restart
;;
esac
;;
HARD)
echo -e "Running NTP Query & Restarting NTP Service" "\n"
ntpq -p | mailx -s "HOSTNAME - NTP Query - Restarted NTPD" adminacct@example.com && /usr/bin/sudo /sbin/service ntpd restart
;;
esac
;;
esac
exit 0
Be sure to change HOSTNAME and adminacct@example.com to the client's hostname, and the admin account that you want to email to go to.
Now, the tricky, and probably not the most secure way to do this, is to modify the sudoer's file to allow the nagios user to execute system commands. I'm sure there is a more 'secure' way of doing this, but this works for me.
1. visudo
2. add the following:
User_Alias NAGIOS = nagios,nagcmd
Cmnd_Alias NAGIOSCOMMANDS = /sbin/service
Defaults:NAGIOS !requiretty
NAGIOS ALL=(ALL) NOPASSWD: NAGIOSCOMMANDS
Be sure to restart the nrpe client after all this has been accomplished. Now to move onto the server end of things.
First thing you need to do is create an event-ntp command in the commands.cfg file:
define command{
command_name event-ntp
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTNAME$ -c ev
ent-ntp -a $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
}
This will be called by the event-handler object in your configuration file.
now, modify your service description in wherever you configure your service/host definitions. In my case I have a separate configuration file called linux.cfg.
define service{
use YOUR-service-TEMPLATE
host_name HOSTNAME-HERE
service_description Time Sync Check
event_handler event-ntp
check_command check_nrpe!check_ntp
}
Now restart nagios (service nagios restart), and test the configuration from the server end:
/usr/local/nagios/libexec/check_nrpe -H REMOTEHOSTNAME -c event-ntp -a CRITICAL HARD
If all goes well, you should receive an email from your client with an output from ntpq -p, and an ntpd service restart.
If you have any problems, not receiving email, or not executing the said script, set the debug level=1 on nrpe.cfg, restart nrpe, execute the above event-ntp test, and check your logs.
As you can see, it's not too difficult to execute event-handler scripts, and saves Administrator's time when nagios can do the leg-work on system/host critical alerts. This example 'self-heals' the NTPd service, but can be used/modified to just report data when there is a problem. Any time that nagios can do self-automation/testing, before administrators get to the machine, shaves time off of troubleshooting a problem.
Special Thanks to keith4 on freenode.net's #nagios channel for catching a syntax error for my $HOSTNAME$ argument in my commands.cfg file. Thus saving me many hours of hair pulling and name calling.
One of the most over-looked, but very powerful, features of Nagios is it's ability to use event handlers (Nagios Docs). An Event Handler allows for a script to be executed based on changes to the service/host system state. There are endless possibilities to using this feature. Usually when Nagios alerts to a changed system state (warning/critical), an administrator is emailed/paged/tweeted in response to the system state change. The said administrator then logs in, restarts services, checks network connection, finds out why disk space went critical, so on and so forth. Event-Handler's can do this and so much more!
I have written numerous event-handler scripts that creates a 'self-healing' environment for different servers utilizing event-handlers and NRPE. Some of the Event handlers that I utilize in Nagios are the following:
*Disk Space Critical - When Nagios alerts to a warning/critical disk space, NRPE executes a custom du-scan.sh script that sorts all of the data on the mount point by highest ammt used, puts it into a log file on the /tmp directory and emails the location of the log to administrators
*CPU Load Critical - When Nagios alerts to a warning/critical CPU Load, whether it's in linux or windows, a script is executed (Bash in linux, VB in windows) that emails administration the top 5 running CPU process's on the server
*NTP (Network Time Protocol) time sync Critical - Sometimes when CPU load goes critical, the NTP service running on a Linux machine goes WAY out of sync (over 1000seconds) causing the NTP Daemon to crash. When the time is off on the server, the various services we use, report different times, causing even more issues. The fix to this, is to have Nagios restart the ntp service on the remote server via NRPE.
This little blog entry will detail how to setup an NTP event-handler for Nagios. You can use this as a base for just about anything else event-handler related.
This is written with the assumption that the person using this is already familiar with, and has a Nagios Server utilizing NRPE for linux clients, along with having nagios-plugins installed on the client. This isn't a basic 'nagios howto' at all.
First things first, setting up and configuring the remote client for allowing command arguments.
1. Navigate to your nrpe source directory (in this case: /root/Download/nrpe2-12/
2. Reconfigure nrpe for command arguments
./configure --enable-command-args && make && make install
3. Modify the nrpe.cfg file
a) change: dont_blame_nrpe=0 to: dont_blame_nrpe=1
b) add the following to your command arguments:
## /usr/local/.... is the path to the check_ntp plugin that comes with nagios plugins, change 0.pool.ntp.org to the ntp server that your organization uses to get ntp data. Warning at 10 seconds, critical at 20 seconds.
command[check_ntp]=/usr/local/nagios/libexec/check_ntp -H 0.pool.ntp.org -w 10 -c 20
## /usr/local/.... is the path to the event-ntp handler, as seen below.
command[event-ntp]=/usr/local/nagios/libexec/event-ntp $ARG1$ $ARG2$ $ARG3$
4. create a file called event-ntp, u:g of nagios:nagios, set executable.
5. Drop this code into the event-ntp file:
#!/bin/bash
## This is an event handler that will be executed on Warnings and Critical alerts.
## On Warnings, an ntp query will be issued, and the email will be sent to the specified admin
## On Critical, an ntp query will be issued, and the ntpd service will be restarted to re-sync the clocks
case "$1" in
OK)
;;
WARNING)
echo -e "Running NTP Query" "\n"
ntpq -p | mailx -s "HOSTNAME - NTP Query" adminacct@example.com
;;
UNKNOWN)
;;
CRITICAL)
case "$2" in
SOFT)
case "$3" in
3)
echo -e "Running NTP Query & Restarting NTP Service" "\n"
ntpq -p | mailx -s "HOSTNAME - NTP Query - Restarted NTPD" adminacct@example.com && /usr/bin/sudo /sbin/service ntpd restart
;;
esac
;;
HARD)
echo -e "Running NTP Query & Restarting NTP Service" "\n"
ntpq -p | mailx -s "HOSTNAME - NTP Query - Restarted NTPD" adminacct@example.com && /usr/bin/sudo /sbin/service ntpd restart
;;
esac
;;
esac
exit 0
Be sure to change HOSTNAME and adminacct@example.com to the client's hostname, and the admin account that you want to email to go to.
Now, the tricky, and probably not the most secure way to do this, is to modify the sudoer's file to allow the nagios user to execute system commands. I'm sure there is a more 'secure' way of doing this, but this works for me.
1. visudo
2. add the following:
User_Alias NAGIOS = nagios,nagcmd
Cmnd_Alias NAGIOSCOMMANDS = /sbin/service
Defaults:NAGIOS !requiretty
NAGIOS ALL=(ALL) NOPASSWD: NAGIOSCOMMANDS
Be sure to restart the nrpe client after all this has been accomplished. Now to move onto the server end of things.
First thing you need to do is create an event-ntp command in the commands.cfg file:
define command{
command_name event-ntp
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTNAME$ -c ev
ent-ntp -a $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
}
This will be called by the event-handler object in your configuration file.
now, modify your service description in wherever you configure your service/host definitions. In my case I have a separate configuration file called linux.cfg.
define service{
use YOUR-service-TEMPLATE
host_name HOSTNAME-HERE
service_description Time Sync Check
event_handler event-ntp
check_command check_nrpe!check_ntp
}
Now restart nagios (service nagios restart), and test the configuration from the server end:
/usr/local/nagios/libexec/check_nrpe -H REMOTEHOSTNAME -c event-ntp -a CRITICAL HARD
If all goes well, you should receive an email from your client with an output from ntpq -p, and an ntpd service restart.
If you have any problems, not receiving email, or not executing the said script, set the debug level=1 on nrpe.cfg, restart nrpe, execute the above event-ntp test, and check your logs.
As you can see, it's not too difficult to execute event-handler scripts, and saves Administrator's time when nagios can do the leg-work on system/host critical alerts. This example 'self-heals' the NTPd service, but can be used/modified to just report data when there is a problem. Any time that nagios can do self-automation/testing, before administrators get to the machine, shaves time off of troubleshooting a problem.
Special Thanks to keith4 on freenode.net's #nagios channel for catching a syntax error for my $HOSTNAME$ argument in my commands.cfg file. Thus saving me many hours of hair pulling and name calling.
Monday, September 21, 2009
OpenSimulator
Last week I was tasked with attempting to create a 'virtual world' for a training environment. Full on PowerPoint Slides, VOIP, etc in a training room type environment. Well, as I have never really played with SecondLife, or any other type of Virtual World, I did some digging.
It looks like VirtualWorld environment's are the next big thing (and they still are 8+ years later since SecondLife came out). More and more I read articles online how big companies such as IBM, Sun and HP are using SecondLife (and their own internal Virtual World Servers) to host conferences, webcasts, and training sessions for their staff and the public.
As a matter of fact, not only are companies using Virtual Worlds to host various public functions; but also creating 'Virtual Data Centers'. Case in point, IBM's Virtual Data Center. IBM has special software that allows System's Administrators to monitor and administer their Data Centers, in a virtual environment.
So, while surfing around the internet for VirtualWorld servers, I came across OpenSimulator. You can create a stand-alone server, or attach it to other virtualworlds through osgrid.org. As the developers do their testing in Ubuntu, I downloaded and installed the latest Ubuntu Server and started up OpenSimulator. The wiki page located on their website is pretty self-explanatory, walking you through step-by-step on setting up your own virtual world.
The one problem that I did come across, was using either the Hippo Viewer or SecondLife Client to connect to the Instance. Both Hippo Viewer and SecondLife Client had my avatar as a 'ghost'. I found that other people had these problems, and the solution was to create hair for your avatar, and the ghost would go away. Strange Quirk, but it worked!
I wouldn't have been able to get this setup and troubleshooted without the excellent help from freenode.net's #opensim channel. They were a big help, even at 2200hrs MST.
Anyway, now that I have my opensim server running in Ubuntu, on a virtualbox; it's time to create some land!
Until next time.....
It looks like VirtualWorld environment's are the next big thing (and they still are 8+ years later since SecondLife came out). More and more I read articles online how big companies such as IBM, Sun and HP are using SecondLife (and their own internal Virtual World Servers) to host conferences, webcasts, and training sessions for their staff and the public.
As a matter of fact, not only are companies using Virtual Worlds to host various public functions; but also creating 'Virtual Data Centers'. Case in point, IBM's Virtual Data Center. IBM has special software that allows System's Administrators to monitor and administer their Data Centers, in a virtual environment.
So, while surfing around the internet for VirtualWorld servers, I came across OpenSimulator. You can create a stand-alone server, or attach it to other virtualworlds through osgrid.org. As the developers do their testing in Ubuntu, I downloaded and installed the latest Ubuntu Server and started up OpenSimulator. The wiki page located on their website is pretty self-explanatory, walking you through step-by-step on setting up your own virtual world.
The one problem that I did come across, was using either the Hippo Viewer or SecondLife Client to connect to the Instance. Both Hippo Viewer and SecondLife Client had my avatar as a 'ghost'. I found that other people had these problems, and the solution was to create hair for your avatar, and the ghost would go away. Strange Quirk, but it worked!
I wouldn't have been able to get this setup and troubleshooted without the excellent help from freenode.net's #opensim channel. They were a big help, even at 2200hrs MST.
Anyway, now that I have my opensim server running in Ubuntu, on a virtualbox; it's time to create some land!
Until next time.....
Tuesday, September 15, 2009
Linux Screen template
It's been awhile since I have posted anything, but hopefully I will start posting little tidbits of helpful *nix stuff again.
This time, the post is about Linux Screen templates. With more and more linux Distro's going GUI, and trying to get away from the CLI; the screen program has been mostly overlooked. As I have been working in and around linux for the last
12 years or so, I have become quite fond of the screen application.
First things first: man screen
Everything you need to know about custom .screenrc 's is located in the man page, lo and behold, many people don't realize this.
To create a .screenrc that I use every day:
touch /home/username/.screenrc (or /root/.screenrc for root's screen)
vi .screenrc
hardstatus alwayslastline "%{=b}%{G} Screen(s): %{b}%w %=%{kG}%C%A %D, %M/%d/%Y"
startup_message off
msgwait 1
Save and quit the editor, and fire up screen. This will show all of the screens that you have open (Name each one you create with: Ctrl-a A), and puts in a date/time stamp in the lower right hand corner. I put this in because I get so busy that I hardly look up at the clock and end up missing lunch. This way I can easily look over to the right to check my time :-)
As I am using a GIANT monitor, my screen capture of what my screen session looks like here in Blogger, seems to be all wacky. You should be able to click on the image to view it.

As I said, I live by screen for server work. I can create multiple screens, split them Horizontally or Vertically into 1 main screen, detach a screen when I go home, VPN in and re-attach the said screen from another location. And because I spend most of my time in a console, having a custom screenrc file, just make sense.
This time, the post is about Linux Screen templates. With more and more linux Distro's going GUI, and trying to get away from the CLI; the screen program has been mostly overlooked. As I have been working in and around linux for the last
12 years or so, I have become quite fond of the screen application.
First things first: man screen
Everything you need to know about custom .screenrc 's is located in the man page, lo and behold, many people don't realize this.
To create a .screenrc that I use every day:
touch /home/username/.screenrc (or /root/.screenrc for root's screen)
vi .screenrc
hardstatus alwayslastline "%{=b}%{G} Screen(s): %{b}%w %=%{kG}%C%A %D, %M/%d/%Y"
startup_message off
msgwait 1
Save and quit the editor, and fire up screen. This will show all of the screens that you have open (Name each one you create with: Ctrl-a A), and puts in a date/time stamp in the lower right hand corner. I put this in because I get so busy that I hardly look up at the clock and end up missing lunch. This way I can easily look over to the right to check my time :-)
As I am using a GIANT monitor, my screen capture of what my screen session looks like here in Blogger, seems to be all wacky. You should be able to click on the image to view it.

As I said, I live by screen for server work. I can create multiple screens, split them Horizontally or Vertically into 1 main screen, detach a screen when I go home, VPN in and re-attach the said screen from another location. And because I spend most of my time in a console, having a custom screenrc file, just make sense.
Subscribe to:
Posts (Atom)