- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Perl script needed
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-19-2011 10:31 PM
тАО04-19-2011 10:31 PM
I have a curl call which gets me the following output:
curl http://hostname1.qa.com:8888/getlist
OUTPUT -
{
"token" = "201119041112";
"apps" = {
"PaymentApp" = "http://hostname1.qa.com:2333/cgi-bin/Jboss/PaymentApp-EMEA.woa/paymentInfo";
"OrderConsumer" = "http://hostname.qa2.com:2345/apps/orders";
...
};
}
Based on the curl call which is being made to a specific URL , I need to parse out URL entries which are of similar pattern as the URL to which the call was made (http://hostname1.qa.com) -
I need to scrub out only entries which have hostname1 in them.
Then I need to populate a couple of properties files which look like this with the appname (e.g. PaymentApp) , URL(http://hostname1.qa.com:2333), host(hostname1.qa.com) , port(e.g. 2333) , env (e.g. qa) information that I gathered from above -
file1 -
define service{
host_name $hostname
use generic-service
servicegroups preprod apps
service_description $appname
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 2
retry_check_interval 1
contact_groups admin
notification_interval 120
notification_period 24x7
notification_options w,u,c,r
process_perf_data 0
check_command url-check_$env_$port
}
file2 -
define command{
command_name url-check_$env_$port
command_line $USER1$/url-check -H $hostname -p $port -r added --regex=alive -t 4
}
I have a way of doing this in shell and now looking for a way to do this in perl.
Thanks,
Allan.
Solved! Go to Solution.
- Tags:
- curl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2011 04:39 AM
тАО04-20-2011 04:39 AM
Re: Perl script needed
> I have a way of doing this in shell and now looking for a way to do this in perl.
OK, so...
If I had to guess, I'd guess that this is all about Nagios and a plan to refactor shell scripts into pure Perl. Correct?
It's not going to help you (or me) if I provide full-blown solutions for you. You will be better served by trying and learning by trail-and-error. If you are serious, and you haven't already looked here, do so:
http://www.perl.org/learn.html
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-20-2011 06:00 AM
тАО04-20-2011 06:00 AM
Re: Perl script needed
although the curl output already seems to be quite ordered which maybe suggests to better make up some parsing grammar and feed modules like Parse::RecDescent or similar with it, one could tinker up some weird regexp like this to capture the items you are interested in:
open CURL, "/usr/bin/curl $fetchurl |"
or die "cannot pipe from curl\n";
while (<>) {
if (my ($app, $url, $host, $env, $port) = $_ =~
m{"([^"]+)"\s+=\s+"?(http://(hostname1)\.([^.]+)\.[^:]+:(\d+)/.*)}) {
# process $app, $host, $url, $port, $env etc. here
}
close CURL;
However, I would reconsider if you really want to define a separate Nagios service object for each parsed URL.
I probably would rather define a single service object and use a check_multi check command on it.
(see http://my-plugin.de/wiki/projects/check_multi/start , sorry not clickable to preserve code spacing)
You could also define custom variable macros which you could refer to as e.g. $_HOSTMY_CUSTOM_MACRO$ in a single service definition.
See http://nagios.sourceforge.net/docs/3_0/customobjectvars.html
And don't forget that you can pass arguments to your check command as well like
define service {
...
check_command url-check!$_HOSTENV$!$_HOSTPORT$
}
But probably there isn't much gain because this way you would have a host of host definitions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-21-2011 12:16 PM
тАО04-21-2011 12:16 PM
Re: Perl script needed
Here is what I have currently -
curl http://host.domain.com:8000/Jboss/Service.jbs/america?method=geturls|grep host.domain.com |awk '{print $1,$3}'
"OrderApp" "http://host.domain.com:8100/apps/Orderinfo";
"EmailAppTest" "http://host.domain.com:5100/apps/email";
...
...
I need to strip out the following words -
OrderApp host.domain.com 8100
EmailAppTest host.domain.com 5100
...
...
So appname , host & port from above.
Then once I have that I can echo that to generate properties files through a while loop.
Thanks,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-21-2011 12:49 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-21-2011 01:02 PM
тАО04-21-2011 01:02 PM
Re: Perl script needed
The matching can differ so I need a generic solution.
Regards,
Allan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-21-2011 01:17 PM
тАО04-21-2011 01:17 PM
Re: Perl script needed
> The matching can differ so I need a generic solution.
Of course, you said that. Try:
# perl -nle 'm{"(.*?)".*?//(.*):(\d+)/} and print "$1 $2 $3"' file
Regards!
...JRF...