Archive

Archive for the ‘Uncategorized’ Category

ZSH: Create dynamically associatives array in a function

July 14th, 2010 No comments

I’m currently working on some scripts to create CSV files (to import into iTop, I’ll post about it in few weeks) from data received via snmp. To make things propers, I want to reuse my code as far as possible, so I was looking for a way to create some associatives array in a function, where the array name is give as argument.

Thanks to the ZSH IRC channel (special thanks to ft) here a way to achieve that:


mytest() {
typeset -A -g $1
buffer="$1[$2]"
: ${(P)buffer::=$3}
}

so, the following sample code:


mytest() {
typeset -A -g $1
buffer="$1[$2]"
: ${(P)buffer::=$3}
}

mytest toto 3 42
mytest tutu 4 43

print -l $toto[3]
print -l $tutu[4]

will display 42, and then 43!

One final word: zsh is magic.

Categories: Uncategorized Tags:

Splunk: useful URL

July 11th, 2010 No comments

as you probably already know IRC is good to learn things, here some URL I learn from the splunk channel:

  • http://host:webport/en-US/debug/refresh reload some parts of splunk, including applications’s views. Very useful when developing a new application. No need to restart each time!
  • https://host:8089/services/admin/inputstatus/TailingProcessor:FileStatus display the status of file monitorings. Note the port is the manager one, not the webone, so I guess this interface is available on agents even if splunkweb is not started. You can hit /services/admin/ to find another log of informations.

Categories: Uncategorized Tags:

Nagios: check_ldap on Solaris

March 29th, 2010 1 comment

A personal note about how to get check_ldap (Nagios’s plugins) on Solaris, you simply need to edit the configure file itself to remove -llber from the line LIBS=”-lldap -llber $LIBS”. You also need to execute the following commands:

perl -i -pe ‘s/-lldap -llber/-lldap/g’ **/*Makefile

Cheers!

Categories: Uncategorized Tags:

varnish: Send a client always on the same backend

March 9th, 2010 No comments

I’m now very close to migrate from akamai to varnish at work. However, since we doesn’t have session replications on the application server, I was required to send a client always on the same backend, even if the user is not authentified. In a first try, we thought about use a cookie, valued by the name of the server, and write some VCL to define the backend based on the cookie value.

However, thanks to the varnish developper (through the channel) phk pointed me they’re working on a director method to implements this behavior. While this feature is not yet available on a release, it’s present in the trunk (I’m using r4602).

Here the source code:

if (vs->criteria == c_client) {
/*
* Hash the client IP# ascii representation, rather than
* rely on the raw IP# being a good hash distributor, since
* experience shows this not to be the case.
* We do not hash the port number, to make everybody behind
* a given NAT gateway fetch from the same backend.
*/
SHA256_Init(&ctx);
AN(sp->addr);
SHA256_Update(&ctx, sp->addr, strlen(sp->addr));
SHA256_Final(sign, &ctx);
hp = sign;
}

Here how to define your director:

director rtl client {
{ .backend = www1rtl; .weight = 1; }
{ .backend = www2rtl; .weight = 1; }
}

Categories: Uncategorized Tags:

OpenSSO strict cookie value

February 22nd, 2010 1 comment

At my work, we’re currently working on a new J2EE platform to host our webapp applications, based on Tomcat 6 (6.0.24 to be precise). After deployed few fully public webapps without any issue, we start to deploy some other webapps with an authenticated part. The authentication is based on OpenSSO, using REST APIs. The cookie is created to OpenSSO, then set (client side) by one of our own webapplication. This cookie is validate using isValidToken REST API on every application the user goes. However, we’re not able to get authentication working on the preproduction environment, while it working perfectly on the dev environment. After some investigations with the developpers, we notice the OpenSSO’s cookie value was truncated.

After reading this post on the tomcat’s user mailing list, we start to configure tomcat. Few hours after, I was thinking about change the tomcat configuration is only a workaround, without fixing the original problem. Thanks to the OpenSSO’s IRC channel, someone (Allan Foster) pointed me to com.iplanet.am.cookie.c66Encode configuration variable. You can enable it in the console, Configuration, servers and sites, click on default paramaters, and then advanced tab. Set the value to true, and voila! Everything is now working good!

Categories: Uncategorized Tags:

Using it’s all text on Mac OS X

September 15th, 2009 7 comments


Introduction

As a system administrator, I dislike to edit text in Firefox (or any other webbrowser), for example to write a new post on this blog, or edit some contents in drupal. This morning, I was looking for a Firefox extension allowing to use an external editor (in my case vim, for sure) to edit contents of textarea. This extension is pretty simple, you only need to configure which command to run to edit the file.

However there is a big trouble with Mac OS X, indeed, I was not able to find a command line to open a new terminal tab and lauching vim with the file to edit. Indeed, something like:


% open -a iTerm /usr/bin/vim

is working fine, however, it’s not possible to do something like:


% open -a iTerm /usr/bin/vim -- /tmp/file_to_edit

That’s very inconvenient, isn’t it! So, the only way I found to achieve that is to write an AppleScript to open a new iTerm, using vim profile (which runs vim as startup), and then open the file by sending text to vim from the AppleScript. But, once gain, I run out of luck. Indeed, the filename computed by it’s all text contains spaces, and vim expect escaped spaces. So, I look for a way to replace string in AppleScript, but… guess what? it’s seem very difficult (because I need to create another file..). So the only simple solution I found is to create a shell script that create a symbolic link in /tmp to the file to edit.. Here we go!

Configuration

iTerm
Open your bookmarks manager, and create a new bookmark like
that:

Image 8

Open a terminal, create the directory ~/bin, create the file
editfile with the following contents (replace bbonfils
with your login name):

#!/bin/zsh
 
extension=${1:e}
link="/tmp/firefox."$$".${extension}"
 
ln -s "$1" $link
 
/Users/bbonfils/bin/editfile.scpt $link

Create a new file named editfile.scpt with the following contents:

#!/usr/bin/osascript

on run argv
        tell application "iTerm"
                activate
                make new terminal
                tell the last terminal
                        launch session "vim"
                        tell the last session
                                write text "^[[:e " & item 1 of argv
                        end tell
                end tell
        end tell
end run

Ensure both are executable chmod +x, and then configure it’s all text
to use the first script to open file (/User/bbonfils/bin/editfile), and
now it should work!

The last word

Note I can’t remove the link in the script, since all of them are executed in background,
if you add a rm in the think, the link will be removed few seconds after you start vim,
so your textarea contents won’t be updated.

And yes, I know, it’s ugly, if you have a better way to achieve that, please post it in comments!

Categories: Uncategorized Tags: ,