Language: Ruby

Untitled Ruby (6-Apr @ 01:09)

Syntax Highlighted Code

  1. Óà‰NDƒÁ?‰>‰n ??Uÿj?‰F@H‰FH¸«ªªª‰V(÷áÑê‰VL‹G(UPÿW ‹N ‰F,‹W(j?QRÿW ‰F4‹F@‹O(j?PQÿW ‰F8??K?¸? j?Óà‰†??? ‹W(PRÿW ‹N,ƒÄ0…ɉF?tP‹N4…ÉtI‹N8…ÉtB…Àt>‹Ž??? W‹ÑÆF??Ñê???P???H?ȉ–˜? ‹T$,‰ŽŒ? ‹L$?‰V|‰Nxè1 ƒÄ?_^][áìÚ ?W‰G?èû? ƒÄ?¸üÿÿÿ_^][Ã_^]¸úÿÿÿ[Ã????????‹D$?3É;ÁVta‹p?;ñtZ9H tU9H$tP‰H?‰H?‰H?Ç@,? ‹V?‰N?‰V ‹V?;Ñ}?‰N?‹V?V÷Ú?ÒƒâGƒÂ*‰V?Ç@0? ‰N?èÑ6 Vè?? ƒÄ?3À^øþÿÿÿ^Ã??????????????????????????S‹\$?UV…ÛW?„“? ‹s?…ö?„ˆ? ‹l$?ƒý????{? …í?Œs? ‹C …À?„_? ƒ; u?‹C?…À?…O? ‹F?=š? u ƒý??…<? ‹K?…Éu?¡ðÚ ?_^‰C?]¸ûÿÿÿ[ËN?ƒø*‰?‰L$?‰n?ux‹N$‹FxÁá ??é x HÑøƒø?v?¸? Áà??È‹F`…Àt?ƒÉ ‹Á3Ò¿? ÇF?q ÷÷+Ê?ÏQVèà? ‹F`ƒÄ?…Àt?‹S0Áê?RVèÉ? ‹C0%ÿÿ PVèº? ƒÄ?ÇC0? ‹F?…Àt?SèÓ? ‹C?ƒÄ?…Àu3ÇF?ÿÿÿÿ_^]3À[ËC?…Àu?;l$???ƒý?t?‹
  2. Contribute a better translation

Plain Code

Óà‰NDƒÁ?‰>‰n ??Uÿj?‰F@H‰FH¸«ªªª‰V(÷áÑê‰VL‹G(UPÿW ‹N ‰F,‹W(j?QRÿW ‰F4‹F@‹O(j?PQÿW ‰F8??K?¸? j?Óà‰†??? ‹W(PRÿW ‹N,ƒÄ0…ɉF?tP‹N4…ÉtI‹N8…ÉtB…Àt>‹Ž??? W‹ÑÆF??Ñê???P???H?ȉ–˜? ‹T$,‰ŽŒ? ‹L$?‰V|‰Nxè1 ƒÄ?_^][áìÚ ?W‰G?èû? ƒÄ?¸üÿÿÿ_^][Ã_^]¸úÿÿÿ[Ã????????‹D$?3É;ÁVta‹p?;ñtZ9H tU9H$tP‰H?‰H?‰H?Ç@,? ‹V?‰N?‰V ‹V?;Ñ}?‰N?‹V?V÷Ú?ÒƒâGƒÂ*‰V?Ç@0? ‰N?èÑ6 Vè?? ƒÄ?3À^øþÿÿÿ^Ã??????????????????????????S‹\$?UV…ÛW?„“? ‹s?…ö?„ˆ? ‹l$?ƒý????{? …í?Œs? ‹C …À?„_? ƒ; u?‹C?…À?…O? ‹F?=š? u ƒý??…<? ‹K?…Éu?¡ðÚ ?_^‰C?]¸ûÿÿÿ[ËN?ƒø*‰?‰L$?‰n?ux‹N$‹FxÁá ??é x HÑøƒø?v?¸? Áà??È‹F`…Àt?ƒÉ ‹Á3Ò¿? ÇF?q ÷÷+Ê?ÏQVèà? ‹F`ƒÄ?…Àt?‹S0Áê?RVèÉ? ‹C0%ÿÿ PVèº? ƒÄ?ÇC0? ‹F?…Àt?SèÓ? ‹C?ƒÄ?…Àu3ÇF?ÿÿÿÿ_^]3À[ËC?…Àu?;l$???ƒý?t?‹
Contribute a better translation

test2132 (5-Mar @ 10:39)

Syntax Highlighted Code

  1. puts "anil"

Plain Code

puts "anil"

Untitled Ruby (5-Mar @ 10:27)

Syntax Highlighted Code

  1. puts "anil"

Plain Code

puts "anil"

Untitled Ruby (12-Jan @ 20:58)

Syntax Highlighted Code

  1. class MCollective::Application::Facts<MCollective::Application
  2.     description "Reports on usage for a specific fact"
  3.  
  4.     # this will be available in configuration[:fact]
  5. [51 more lines...]

Plain Code

class MCollective::Application::Facts<MCollective::Application
    description "Reports on usage for a specific fact"

    # this will be available in configuration[:fact]
    option :script,
        :description    => "Fact to report on",
        :arguments      => ["--fact FACT", "-f FACT"]

    def post_option_parser(configuration)
        configuration[:fact] = ARGV.shift if ARGV.size > 0
    end

    def validate_configuration(configuration)
        raise "Please specify a fact to report for" unless configuration.include?(:fact)
    end

    def show_single_fact_report(fact, facts, verbose=false)
        puts("Report for fact: #{fact}\n\n")

        facts.keys.sort.each do |k|
            printf("        %-40sfound %d times\n", k, facts[k].size)

            if verbose
                puts

                facts[k].sort.each do |f|
                    puts("            #{f}")
                end

                puts
            end
        end
    end

    def main
        rpcutil = rpcclient("rpcutil", :options => options)
        rpcutil.progress = false

        facts = {}

        rpcutil.get_fact(:fact => configuration[:fact]) do |resp|
            begin
                value = resp[:body][:data][:value]
                if value
                    facts.include?(value) ? facts[value] << resp[:senderid] : facts[value] = [ resp[:senderid] ]
                end
            rescue Exception => e
                STDERR.puts "Could not parse facts for #{resp[:senderid]}: #{e.class}: #{e}"
            end
        end

        show_single_fact_report(configuration[:fact], facts, options[:verbose])

        printrpcstats
    end
end

Untitled Ruby (20-Jun @ 02:53)

Syntax Highlighted Code

  1.    =     F          8 6 k j i h = 9 8 7 6 5 g @ ? > < 3 2 1 0 /   
  2.   
  3.    !<^K?ÔöÈ&;}>zÄ[€°4qÞ\íháËEª#­…2   !#Å@»-EC*¥ÌC¥°(Ž!Z/ê,ZÍ<ÅO{`§   !~câp[üÎŒ·”^ŽÈÙ¢õ$r³;Ânî+a½þü       !€³3!gË2èYwQADü‰Ê£ ò˜!æ¬sÕÍ•   !;(¶²­DUªŠo›ýÚÊ]AÉcQȇßP1õ¤|ãkÇú   !z÷=ÍÌ)ë´/gŒê„E}|/ñ&3àH    ü^£="­ƒ   !&ŒÆ¿˜²ñqìàŠ°ï´P*0%Æ%…6 -6o[á   !õ¯¥øy‰³8ͺOœþèaQä:’ð¦ÑݾÒ   !¦‚6à\ü\°ûp‡çöæ&ëd&]š{}úfs =ñs'ÁZ   !z<Ä>SþTbå²û–Œ0<Ce¸Ük¸ùskN’.8]   !!‚÷î8®£6L+€/Ós’*õÊ'2¬±uQ¦%ìž   !ÿÉ£9Ih‡-ð@.¨~ÄpT;(±[(2“ ¼˜q8   !èAžÏÖïã QÅ     Ր“lsœ§úü    ´5‹   !ÍJF´Ù
  4. ¼…¥a&w»¶Æäw³·êÀ`Y-Qbwu   !q`Y¦È    >¼`L¸ýÒ¶òÞù}aFgAøãjÇ   !¼Ëƒ“ŽSˆñrÛ|‚X “¢Ã j½ÛFoÒòýJ   !ÿÌ’‘}‘1(
  5. [62 more lines...]

Plain Code

    =     F          8 6 k j i h = 9 8 7 6 5 g @ ? > < 3 2 1 0 /    
   
   !<^K?ÔöÈ&;}>zÄ[€°4qÞ\íháËEª#­…2   !#Å@»-EC*¥ÌC¥°(Ž!Z/ê,ZÍ<ÅO{`§   !~câp[üÎŒ·”^ŽÈÙ¢õ$r³;Ânî+a½þü       !€³3!gË2èYwQADü‰Ê£ ò˜!æ¬sÕÍ•   !;(¶²­DUªŠo›ýÚÊ]AÉcQȇßP1õ¤|ãkÇú   !z÷=ÍÌ)ë´/gŒê„E}|/ñ&3àH    ü^£="­ƒ   !&ŒÆ¿˜²ñqìàŠ°ï´P*0%Æ%…6-6o[á   !õ¯¥øy‰³8ͺOœþèaQä:’ð¦ÑݾÒ   !¦‚6à\ü\°ûp‡çöæ&ëd&]š{}úfs=ñs'ÁZ   !z<Ä>SþTbå²û–Œ0<Ce¸Ük¸ùskN’.8]   !!‚÷î8®£6L+€/Ós’*õÊ'2¬±uQ¦%ìž   !ÿÉ£9Ih‡-ð@.¨~ÄpT;(±[(2“ ¼˜q8   !èAžÏÖïã QÅ     Ր“lsœ§úü    ´5‹   !ÍJF´Ù
¼…¥a&w»¶Æäw³·êÀ`Y-Qbwu   !q`Y¦È    >¼`L¸ýÒ¶òÞù}aFgAøãjÇ   !¼Ëƒ“ŽSˆñrÛ|‚X “¢Ã j½ÛFoÒòýJ   !ÿÌ’‘}‘1(
fhDì¾?>ñ´»ÉsÀå¸QÆ-¯&y   !®?„Šiy‰¶Œ]¢]j™ð’ñ ]m³<ªƒÐô©   !l›Ht@0÷f*e’„ŸHJˆxX!ìyqD© 9Ÿ   !:÷ö×B•gF5R‚[eÔ{|èMåíqPÌÃþ   !¬Týä]À,%#^€U5vÎØ~–é7lwÿÅ.´êICÓË   !ov`¸†¨g,ZÁ§¸E-K¸§È'‘àbÜ›àøuNŽ   !•ÐR@ÛDɘ]éV±cùxDhÑ:`/ß²c±Y‚   !©üƒýò6oÜö­Ø‡t¹ú\­áôÉ֍¯1á#t¯   ![ä[ŸØêÙûaz5#äÓ)ë$ù5Ño^²—b›Æ   !®ÐöȰZEWk/¨ZUõ¢¦Ç…Q绿RÛèQØ   !*ÍYo‹j—!¹÷²´m¾=†°]ŽÌê4¤ƒ©Kjñ   !‘ÉàZD¸HÆž·ƒØi²ó™ÞCäB¶/8á"ÄRKÙç   !
^;fª$vÍù&Kco´–07oMgeŽãÃô¦¿™   !h£7—ÞF÷çäG¨·|Ч    æPä’$ëªè¸ˆ   !§Q)+Ì­ãøæª%çÙYV¯d    ”×ÙcÝøMbÎ0ó   !kôkZĺ!m»½æ£§Fe›XUÏõæ>¸Þà ¡-Ò   !x«k:$tÝbtà2D`$C;C€‚¸-‡E}\¦l   !ɘyÔ_AIoÔ
¯>QZ¹@‘5•`Z–#'¡ß   !srˆ»«³»¦LXÒä¤Ñlâ
âÿ»®ãeë"âl—   !¾œÉ¾Wò8ùn%éIJÕ¤wè2Ó‚·¿a…r;   !ôIÝåƒ#<„=CB³5¸•M¶oê~X¢¹JÜo„ºhŒ~   !eAW„2תñ²$;ï
ö…“FÃ˪VβoQ   !ÅÑÔå;9’E‚äÝp1æàªЄóʾ
J;q¼   !´øgºÓ2HÕ*U®¨«§º„ST«ʯìbît   !ZÃÓ>â †C–£r7žŠu¬g«Dz1ûó4MÒA§   !ÒoJrš-ä»CY_ìzß°ëx‘ò%IñÓ¬z   !¤0è3ß,kúITÒR¤£Þ¯—\Î|;Vüàp   !NËu'Ž€iz¼œK’nOª<;—M26©    Évµ&   !æ}ô8¾Ùx­wok…=—å3†È’Ÿ9e¤z±@eÆéý=   !2¨¼-mZíù¾ô@3£§©%Ñü*ëG“]<p   !,(öX“BÖWÄ …a>®°Ã[¯wFtô"   !{›ˆ×ÚÜŽYrí†Xòìê&¶üÛ’œ4í§n   !,½ñžC™:²Á{œKp]°Â¤Õ0Û    }z̏çÿ˜XZ   !Õ:ûIà7•ošÄ2ÏU¿PÈiÇÐ|J‚5òfì§e   !òä[n\ó•œ:Ü“RYåyë iO±½ï)©%   !ºû÷BÐW¡o¿óž$…ïtbº7    Ê*VA—œõ‘ÿm¢   !ŒóòõwûD!ÈöF!—¹Ác»JÔôRüÿìWwí   !uÆœ=Ëc@ráá5Nȍ±GÁ„{0Gwº©G   !‘c9„­J;QvþP6R…HÓZ`û>O†ä%®P@8   !Ê,p©A
jùç—¬ÞDašG³ª/0ÙRbÿP ­bBm   !}Ä\RÝEïÒH“|L1Rͯý»'žŒmöú Þ   !SÌ„M!ÿ%'$œ.P÷ýì9‡ÂPŒJºîG%€(\_   !•mÁôN€«÷¤óGZjÀi³Òp>rfaßTëðVÔëi   !ÈI’V=âhR¿gSW
9sźçõÿ¨íÅËHÄ   !p—ß’¨:ʃZæE¿®sœê9 y’Û1Sⳙ߆çè   !)œxeçѰ‡Yv%
WS«™kW!£ÇýNŠ„   !=õ9ˆ^8Ž  Ì.ÁÕV#`CÜïSá¯ÀJ°&àsbñ   !¤Ÿ€ÄÚlt uHËí%šSþ¥‚†!”¥=E¶k¤6   !éÖÝK¨j%S„Z|©††Ÿó8’˜î½—(®
)   !@°µÔçÕ¡rÑ_¼Êúq=,ÎF‚:ÛoÖñÈC«#}   !VÏy¨¼ðN“ÎÛF¾7.4Išèp¸ÄEÓl|ê   !_¯ógŸ ¤Æ¹ßªkbýÞé©•ÛMjm=¡UQ•ž’   !ÿ^:(µ™à:D7&G·Ñ“f˜¡aàj¸™rtp9ØÔ   !Þ‡Ð܍)öÓT}‚B«ß–c.ãß±S¢So”U;Íæ   !³Š¼¹Z¢üûyø(]Ö]„ìÍeG9X àb€^   !
=n¨C…±u&©©ú£
asaà°A ö«èbZ)+   !°¶cg‡ˆcŠÒ:÷rvKkñ&¬¿¦\y„©Æ=   !5X¥‚@+,H gÓþ‹¨ˆ$IBQ›˜ªfq9ÉT\A   !):Cp7–؉švû7„¬—á½à/¹‡N¶YtËi   !n±\SË&2p3à×ÈÔð!:Ÿ_•ÎRb: é6éüú   !EЯ#§V,Ð*µÄBy¥v}    ùh«BìpØê¡ë÷¯   !€ÉØéqåθågïwý1¼¥³Søµ<;³lÆ}õ˜   !Ø;}]yoëòúñCX×N•§(‹§±¨”Òv¾^…
   !ÞÚ#Y¥:L_X÷%Öá•Ø    /žbêe'•:ž©†   !Ýhá Åµø~âŸHo'ó.IÝü1Ÿ&ƒÖÝãDz3   !„ÑÌÊÚUq;`oYUZíæîâ—ØBíºÏ|Ɖ¼¼   !\QÈŽðb¾XËlÄîú
·Z€ÁÓ –ü2óËF€   !DZ™ï•XY¬ ù
r2!‰Ù߇Բs¡¥,Äš   !½š:Ÿ«º°Í¬V„Vßµß;´1¿ßÒ¥    ÁU¡   !»ÙQ’ÓÁk<íí}`“7g£¹³V˜¶þƒ‘   !u²ènãÓY·Œ!uÀ‚˜vN=íiZˆ“KdH!®   !€¹CVëeýªTYÑÅ|ÒsÔ‚¹üúÜ:ŽÄùU   !o=+íd‡È‡ÓÁënÞüH߯JÈ›RÊx¸•ó´:   !|¨ÞïRí4ÔGzèŠ$ŽVúÖß`C¤ô”¶²pPBø   !¯C÷ÛžŽO‰Z˾lŒ
”󾋸Ø\äœùëàF‡   !Œ1¨}]XBöð¯ã¸[HÑË·7PM%jÄ7l¹üþã   !Y[Í3üµ!}‘ZÜQ˜+ÔÈ›·"AìŒiv¾;×CŸ   !!˜OöíñdÑ?Iä: ùÙ8H¥glŽñÓ?[í   !xÓ|ä?Å¥    Òî/:V²zW%°Wt¦mPi­þ    :   !=hþ;'>JnV)PN|I²¿Âh~A
&Ñߝéed•»V   !ÝZTþZÁ·ú.LLZZOw¥Ɂ#|åñå~iË   !XJ¡Qçœõ*WÄZ£ Pñ
*<]Ôì©÷qÌb@.   !ÅB;³hÃF¸Y}fJu.½)+*œV6ßÕ Ãg
qw·{   !XÅ4ºY›" [x:ÈæH"ä—Ü„¼åX”ØA   !Ǽ‚sd>L÷(]•rñ”²ûj†·)À…‘Iñ2»öF“ˆ   !a;D„GFàOÿÎ<Ô ïØ"¼²ö*E‰»o¯@¾Wø\”   !Vú|
7»¼AÁH‰¶¸Rüp肟AŒò†}ÎcTM   !iÛ»7ôÏÈC.RºÏI3bmGgdþbŠOŒ“`†   !w•Ú]ód룃5|ºV|Q³7£à…¦––ææz>ç$a   !ìòÀ‘ÊÚ»ü°.Räî(LŠ*É´u­¿nՐv¡   !ç÷Ç@CÄÌöÈàòã0î÷eIÉΆʶTžÜ|6*úéô   !Ö?8W‚ÀÚO‘mQÙ*ñ$²HâaÇð_tä®È|eµ   !ü¼çGÜìyg‡ä¿-LÇ¡`eëè‹Ê‹    X¶iS|Ï   !Î5†&R.V@HÌýµ-õŸ_œ…§ê>üÑ›dÐØ   !¾1=h}/dZmºßé.ÑÀª    ÿê;>áa,Xן   !Ý{§Ü"Ì‹$‘ØÓæÝJ ›]ÊDk8½!Ðe¼¦l   !™QÓEðå¾ÜµñÙ_ê3b++n{4}z=gý–z   !´lLj3¶ïÕä­M@]‹ûÄ“Þ}ÑÁ«Pàÿ   !?ÉÅ*{+#ƒ]‡!.éT2Œ°ë÷«HíHÄÍà   !Pÿ±‹¯­{\W°2ÈåÔý¹Osp…*—ƒÊWþDÀ   !§Ø
аýÄ2N=5Ø;¶¼Œ§0©A&~v×v¨§¾þ   !ÚTÁ„îk—Ër ±cà x›ÌonŸå5”¶jg   !Å;ž.«¹“'œõh¢•ç«ÏAº¿33¿Tyµ|ƒÌI   !¨,rÞÁÈÀßÓ³¥‰ÎC€ªæG¼™?½Õd1   !‘ìE2凝ٴ¸nŸ ²ù³nø:Q=7ÍÕô9ø   !°<``a!–%Ê«Q­ Æwwfè¡V«ÜcÍtÿѯ‰   !8¢Û†…¥Ã¤N>6cn²½Ý?
§™‘]´(‘   !úavÀL,Ë(Ÿ.„Ù…/}›"û\uT½”tJ$   !J¡ßoïÅíܨN?£%/’m&0ÎÕÌÄ&¶ìy†   ! êyxS5a鸃r×{“ÝQXåÆr@ie-¸    Ú   !t#2¦^ŸYOð‡yRu¡¤¼ÀÉö w‹øÄ­@J/   !,³>Ÿ¶áBIÔ¥‰¹¶à*8¼éJ
¹·Ä0ã¼ø   !ã-›³óè䃬ÜöÃvIj­¦jAT%Ï    sDV’Ç?#¥   !®ë˜SQ2†óüBgW¦tä»VÚ–A”ÜÁzÊÙ‘AÑݾ   !üNoӾҏ†€Àç    ÆKŽœ… è7)íûtBŠÜ   !àçÉVH|¢N);†L‘ÂO Óˆ%8Û«Úˆ6Ò)   !•6Øá˜•»ßîr‹ûÎî~Ñ)®±ýÿ /ÄH¹   !B§ia¸Æ0Ïj¸X›‘¥!¶s F9Ø;nOŠÃ¹ª   !­;ŒnûXì|ÒŒØW¯;çý£!Ù<¡ßÑ„w   !@59s¤E:Dzý¤¸¨”›í>¾Ÿ¤‚êÖ$[   !¢l8b1îRÉ«g-!ËE†8þ"«Ìœ¶äí'r­Ö   !”'0®©;Ñû&úÎ7À>Ö1ÑÎLRûØxÆú
à‡   !l’Úrªý¹²x …U»_XÄÚ
J¢¨Í€bœ‡$   !ýy–ÓÖR©ŠçÃH    ¡žÿ™õD{\ÿýgùv h@   !í)ôahZ» aÉØØ¸ ›¤W§‹§°4—8HMèÄbŸå   !e†Ýåc`—œ(ŠkЦ³A诙Éx(NšH   !B™P;ð|ëm¤&„Ü:£qmGSÛ\!`Þ­OÉTxb   !*ÞÔÊc    ™z¬*—_¬
oؐù‡‚¦ú"íøæ‡   !úŠæ°}i%˜º5üµ;p¬†@,+ÖÒ§ý­u÷   !<¥hy<¹²Ål ÷©Dè±(x¸    i+Ýëü§ÿ   !tw³E%ØçøL^—·ÒD0±ScHÏŽ¼"t„ô,y   !ö‹H6`DÚú9ç,&˜a ¾²&‰«nL%eÐ   !Ç"Ü|7¤ÍÓ¸Dà«*ŽŒ¼æWuMai§@s.ÐÍ   !†-»ÒI?ù=¯¯šMËaºs¡»gŸ î×2   !ieä¢gO}2Å?VÛo³|ñc Ó¶¨ëä¡!|è‡hÎ{   !úÄíx—{–±s>Éí6ýL­ðüm ß^ÈCä;   !"}„çO
±Áví[Öþ(…“™7´É¬¦©ÿ®#T¼Læ   !b£hc›^ˆ™«<wáú¡lÕä¼W£ü®M‰+,m«   !ʘ¬Ò#¡žOàWã(jë.ä{½°¥$ÆëËò~iqP   !Ü-ϤèCl‘Í—2zF›’q@y©ˆæ×?z¤   !xè·ÿ»XסÏ/>[ñ¡¢TÔÄ©
}Þ-ÙïÔf„Š7   !á}ÔžZ4¾‹šfvïÌ>‡'÷Ûiæ‘/íb­4TÔq¬   !'ý|o)°:ÕfÚí1Ã$pë¡T1eI™´WsøMþ«   ! è™ä¾äó´ “9iËÖJšØcôšíˆ   !ØMÏOIŸîéø0cÞRO!©Z’¾Ù2.#"Þß^   !(euÑ;¡‰¹7÷#{ƒåÊ,—ªñž^yY€¨Äw¥   !`BwÃî(jg!Øù-0rWÏ9¯9ڐkš?a.ùŒo   !I€Ì‡ë ÈՁ!Õª¬ÂÎÕsâ¸]ù‘}úм·QÚ   !s1ü    áïqÐ7Ø.ݧl~ca‡í¡\õSÍÜ9<   !
ZPtôdÆ4_¿ÇÒ¤)Ýè+d¬¹ž„›wÄÄ?   !Ñž    à· ÍŠ[9K\r^¯H¹™”ºÃ´€ÀrUféE“8   !tÈ ˆ+ÉÀÙ{ÚPvGÄ=ŸYŒ7Y•á6€À]æÞçþ   !§Ö”VŽ"6gÞÖGÝ
ÍžÌUÈ,ÁñÝW, ´r   !n^%9!8Zæà`M»bBÿyÝá½È£ëGR´   !€”‚™ê/ç{¹wÍÔýãëL½sàúkN¸E*…GÂ{   !ô+ O
âÛ5q^°èƇ.±»ŠÉð“hfuö©À¼   !”
ÀeíO {„[XÌÙý õÒäšÞwË
6K$nw   !ǯѱ_    ÍQ3—Ž}ÓË“M
ð˜LOÌݲ   !vâKçæ%/@Ûµ›vÿpÀ…Æ‹®ßÄ5š<iÍëïº   !ù.ìŽ*ÉÞeƹþá¥+¦ºªìÀ$™×mG,Du   !´Ò$­Q·²ñ6ø’Â/.aª²Ûòvϐ1l7—“ëV¶   !Š!iÄ%veҏ®    ù>5Yñ]Ym¶Ëe¶MŽ   !I¥ËS@Ë(™µGŒÃãaÚRïYœ G_ªöúç2N   !7‚EŽä ÿÖÜ o¸ð®÷@×Ö÷’eVNþÌ   !j9Qäâdr6·øŒÙù@
Ì’™9òÖ¥¯†‡   !ëÐQ®Å{‹ÁªO¾Ñ`ö¥¦œ²;ü2 r¸S ß   !'»j 긤×-¼»Y寥AÎRÃx‘,    +±ÓOð   !e˜«ÐÔT–c(„%¥q6V]Í!íU<ñF዁­“Ü
Ü   !*³,-1)‚ ÿFÊ·Óªô_K¾Þ(òâÑÏ—ŠÊ   !Sä§Áu–Ä€F.æÉׯ"¦…€P½´—‡%uGkg   !úd‹µò\±|œJ*®K'·Ü'áƒ@¡´ÂÖ8Aà#O   !Üg€³D vâîì‹Ö‚ðwT´€T¿¿¤€   !‹ULg-¬f†[¢Æš£µ—@h¯¶ÀŸ†â-˜^-Ú':   !lÓÛZÔ¢#²Ü—,~Íj¦¨v!P^¯ÛÇ\_ ¨`+ç   !õH—É*à%>±à6áH­oO<¡\ï+б«%†ô!À   !ž»HÝùä_ñëÀxä-ñë¦î˜ŽÅeü™
ѲD   !ó´]‡gyêU0žÐª÷BNUM*­zÜMÿ4-À   !#œ    ,ïyôAgü*+{D™ýÄÏÇh¯æ–5?‚9   !HT)|÷Òu¢$ò3®›† ZI
œi’ÐÊp9²g   !2¹ÓªÉÕ·¨Aƒfýñ€º¦{ß«c8ëpÿÝΙûI°s   !éþ7CŒí¢d¤R3¾`0Ó\£°Ñ8 Á-Úè{¶ºÃò   !†âz‡ØÊù<Ÿè×w‹5JÁ+ra§¼Õszßù,   !4
û…    ­uýšî…w„ö¾aÕÍT‚0eœoÿæ‹™   !¡„8òåwîìÎþfJC+ß—ÒYãÜ D7~ٝzL@g   !
,$dށ‚êÖ
@ÔœUÓëÿÑЩfâ°yvîD£   !qæÐK‚
9F³ó›K7øL¶’•éAcò†7Ç 4#ôj   !ìK¨ìu©˜rzY§|MjÖÅ€™;löfØ9žv¸    á   !áð·ç-{*Á„%]ª´=ð¬èÎt:¾tZ³Ç¼   !òY&OÏViºý5†ÛMÐ
s8Ìïe×vH|$   !玲éu®¥Ô-à¼*pÜÊ÷V©iv8GØ:—cÙ‹f   !ãÁUíBðÌûÑ$Î˺öêN`ê’Fˆ0T    “"G   !8§‘è7y¼”õr—}!&öJlBëß·BºÑl_˜-»ü   !
Ä&²"¶$V(Q!ˆµæ.A½\ùšè\d—V«o   !Úœ[ññù˜B`¾û»%»LhË×`È#]`@졳   !ì ©--
#ùÇí¥ý:F.…E¯ð~‰)n™Gå†nlÚ   !r7{œ¥¬ÈI²‘Û    ¡jo P¨úOÛsª2®c   !1¼%
‡1Ëü“êChº”Þò!dãxý}    ‚Ø   !,Qgù¥³ª?ZEÒ]ÀW]ÝÌ…A?¥ðÔ¢    !ÊÌsTéRU’åá®j­N @\…/£i¸6J¸–‚ÀJ’Í   !ÓÀ¾×ãÝ_6{ýTc7@U» ¨–ÿôdVGsžd   !µ–CïÙ–‚$ Íq­ê¾¹¸"ÓÞ—Ý-fäÏ3   !Fð/NUÚN,dÏ
ïpMÞþ§(1©Ø[HÆgØ_1Ä   !3qÂEÖ-ð'ÖJz‹Ç;ÖJ-èÃ]t†ny]¾ÀW'   !Xý@Â@q¼F©m§ ›Z#Dë•ÎGŸ]=¿+c   !#Xùò`=³ûú¿õq·éåä34ÐF¶1›—ªc@f   !¶l…ÙX¾ˆC…ª>ªP♀ÚHW÷QžN¯9_Vy   !%\Âüùö×v<]vnS À‰ïÀhjdZçæõ EÊí   !çk    —Qá    V¹Ð§À}ö¬=5Çç÷~I‰öèF   !Æÿ̏;‚†}þSàÿÖmƒtS@™RDZùSžñë   !mKŸ„bE͍çrÌõVt] lo’ýº©Ù~D   !UÞ…0§þ¨k1§½£2Zs‚ÚÄP´bÆyA­ÞÞ’!(   !?8?Z—²JJYË    ¾.±L0·iŽWvé!       !    (Q;_!“†èõ@A UxÏ&•Aìá½³5[åâß   !gÎÙÓsk }{õEþ^Ý¡{”q€˜ŒÊ>0á   !J    ‰ãc‰Ê    '/]VJ¬,¤Èú®}äâ“Q1²l7   !\8K.y«æž±¦™9 YÉ>“ä#Ðyî5Šixñi@   !­,Є.ôÊœ#z    Ÿ@™=}èiusJÑïE×yÖ`   !wkˆ+K:æ™aqɜä ÐT!µ}¥–;WoRZr   !ÊÔÒè×QÍ^–ðòú®@/,WÎíìnUÇ]m˜ÞCM   !²I÷åê}Ÿ2
—½µzí‡i²Ê=1w\Å»ú:¢   !­`ÀyTE‡–$WC,[:}’Ó:2@6ÊÊ cÒ*   !¦å8f“§éãxÒõ;7›ÀJ>È—ª”@L4å 
oi   !tf/^Üo¶7tcºKå^1ö"E™È+çÂk™ƒx   !x¬F}Õ·ái[d—°u`–‰¾Ð{×ðÞÀÄ_Þ?P   !ÛÐdO•pÂ7<Àb¾`¢Ýb4ðVÀ1òw_   !f«öä|»º–ÖfÄÂ$dŸ|4„úU(àÊ„w ’ÝV¶<   !"çËÅXÛu®Ûñî›z±§øe/[×®Ÿ
¹7¼Þ!   !©@Vi8Ë4Õ-¥w÷b0éí t«KjÊV†¼§n­3   !jÛ7ès=ºëˆKŠN‰Åkuˆ)b=©çhOq¿ëO£   !ÌeáS>œdvP`°­Û¦ãùwэV²Dñ¤fW   !s¶P=W%ß9kI57ÿPŒÊ
öw­…¼é¯«
çÀ   !¬2D–Wñ    0W!«¬Ê2¢^¬”—(    Ž‚æG‰íhy¤   !mg8ȁwº'zÃKsŽÓþáÒW pÉ Ð‘`vC>   !™•½#IŒ‘® 6¹ëºdg](:¿YW}©³`cç   !SQøÌóë2ì¥ñQÊGû8Kò!ò¬¹™äýÄ   !¹:}V»<%lã¤wohÌ+ªÊ51%WšŸäP   !5Q×à×4Ïx¡K!>¡Sýø>ÿF«/Ó!Íô¥OB   !PðÃFõd9bZYãþ[%À,Q›Vj8Ó"Þ”ÄÙw‹   !7ZlírK3tÿY1,À
UöÚXb-fY‰ëʃþ¯®î•   !’J¡òZxT‚éÈt£Ôx7à³Å~ÙË‹
³Rü¯A   !Ÿ;/;ñ°·s ›2)˜¢¯qòu«èÖ”,¿Fm­   !Ì›¼õâ°ª\fUÅÕ<Cº Ö‡h•%ɲäN¢Ð   !~gwXa— òW7Ž˜N[÷áµE®¯¸‡Wށ:H1×   !a¸‚j”ÿo$˜™P.±Š¼Wû—÷±3ššoß|Çoe.   !6߀%²®Mà ˜|5ÊdÙTuͰi¢c>Q‹ïï   !Þ|3ã4¤@új¤6Y¸@ÿŸtxè€îè²”ØB]_íÜm   !Ìz#þH!˜–²S€Ö «¯-Eø*<{çÕÁÁ×%§   !öÍÝŒ¸    ÿH1w.Ηn#mr7]Þ¾f ƒ÷   !«Ùƒ‰OUœއ(´µ¦ª¹ˆeR¼zÞØû^í9y„   !éøjfL.çíö"w¸UšçkÒÜ-ödîãøJo²ò   !<^K?ÔöÈ&;}>zÄ[€°4qÞ\íháËEª#­…2   !•¿™OÞG1Y•ޤè±dº´£?ÀŽ÷ŽÁ#²   !ÃH=H$©lôín ÎU2WbyxIt ê·ƒš_¢`   !¦ñ%Lѯµ§ÝþŸ²ýp½¶þåì鎴w²/   !ƒžˆòŸ²R/rFÁÿ ÁT ßù¹Ÿº:;ìûyn   !¶Ç£åªd]ëÿ[ FïjÅ4C°oG«è%YÖwZkr;   !’ð¾Ïˆ[c¼ÕSé®Zuî¼RŒY,9ï\R揗w¦³   !ù½ä°cË;a5#?Õqش铱êí•\˜êóº¶3¶   !KŽ=_B+i­PQKD
ÉíÖáÍwÅ–'ûè   !    ó@0Ak¬&Î' {^âÇî5M‡    8ãV1SX3   !H‚0<Ä´»ô+Ìïk‹J"R›+ÄôÓV„ƒÒ_wF   !’¾H…®ä¶ý£Þ‹Ô
(壮Ʋ}¿ 1Ÿšß£
   !«>ÌñBf
~Zò~÷|`°¬âBšÕ¹ad–‘×ùîî   !ÓÓ1>¬c
ì*Rµ¨&(ŸÌ_׫À~ロ5cÝ 6V   !gÉ'©9ÄaJ`Q#Ó2bBSªÂéiÚ¢ÆeYq;   !pŠÿSžçÏ(>ëÛ¨³ù³'Òan)Á úÿwª…"/!˜i   !<š<âyt=
½ªc˜ã
ñ|«Š    tþ}ÀÙ‰«Æ„Þ   !ç¡Û_gÙ‡âÎ
ϤÌI%õ=9rÌþByÌGþC^¤   !ºŒpMæýïe(B‡ÎU¿ø=×–¦ŠÄuP˶^b   !ÓHE´@ ›l{ïN½•ÄoYx‹–"ê{ aÛ   !f¬EƼ×Ò2ØÏf"ð<ÙÆ@ëåVÀš†ïÏ(«“í   !#ôãtQÙ|ž‚!5Çô”ÓãÕÞ3-¥*ÏXSSKàñ   !cîÐÝ4¢ø:úc€©ÉtS”Džë_jo»zܝՆ   JH    ©@Vi8Ë4Õ-¥w÷b0éí t«KjÊV†¼§n­3I    http://crl.verisign.com/pca3.crl   UH    \8K.y«æž±¦™9 YÉ>“ä#Ðyî5Šixñi@I   +http://svrintl-crl.verisign.com/SVRIntl.crl   RH    ¦å8f“§éãxÒõ;7›ÀJ>È—ª”@L4å 
oiI   (http://crl.verisign.com/Class3NewOFX.crl   _H    °<``a!–%Ê«Q­ Æwwfè¡V«ÜcÍtÿѯ‰I   5http://crl-2.trust.teliasonera.com/soneraclass2ca.crl   http://ocsp.turktrust.com.tr   http://ocsp.wisekey.com/   http://validation.diginotar.nl   2p       Oõüq   certs.opera.comr     »s   ô

Untitled Ruby (11-May @ 13:36)

Syntax Highlighted Code

  1. :hierarchy:
  2.     - %{environment}/%{line}-wsps/%{tcname}
  3.     - %{environment}/%{line}
  4.  
  5. [34 more lines...]

Plain Code

:hierarchy:
    - %{environment}/%{line}-wsps/%{tcname}
    - %{environment}/%{line}

intra3.yaml line specific stuff, like what tomcats should be here
wsps:
  mygreatapp1:
    tcname: 'tc7_test1'
  superapp2:
    tcname: 'tc7_tasd1'


then a yaml for each tomcat or application
cat tc7_test1.yaml
---
vhostname: 'test1'
portrange: '123'
jvm_params:
  xmx: '2048'
  xms: '1024'
db_cons:
  sd_puppet:
    type: 'mysql'
    jdbc: 'puppet_db'
    dbserver: 'asdasd'
    dbport: '3306'
    user: 'puppet'
    password: 'bnW$asd'
    #max_active: 50
    max_idle: 16
    #init_size: 5
  sddsd_puppet2:
    type: 'mysql'
    jdbc: 'puppet_db2'
    dbserver: 'asdsd'
    dbport: '3306'
    user: 'puppet'
    password: 'asdljdlasld'

Untitled Ruby (11-May @ 13:30)

Syntax Highlighted Code

  1. class wsp::mysql {
  2.   $line = 'intra3'
  3.   $wsps = hiera('wsps')
  4.   #notify { "wps: $wsps": }
  5. [46 more lines...]

Plain Code

class wsp::mysql {
  $line = 'intra3'
  $wsps = hiera('wsps')
  #notify { "wps: $wsps": }
  create_resources(wsp::mysql::finddb, $wsps)

}

define wsp::mysql::finddb ($tcname=$tcname) {
  #notify { "tcname: $tcname": }
  #notify { "environment: $environment": }
  $db_cons = hiera('db_cons', '')
  #notify { "db_cons: $db_cons": }
  #db_cons: {"enbw_puppet2"=>{"user"=>"puppet", "jdbc"=>"puppet_db2", "type"=>"mysql", "dbport"=>"3306", "password"=>"asdljdlasld", "dbserver"=>"asdadasd"}, 
"enbw_puppet"=>{"user"=>"puppet", "max_idle"=>16, "jdbc"=>"puppet_db", "type"=>"mysql", "dbport"=>"3306", "password"=>"asdasd$ETEUn", "dbserver"=>"asdasd"}}
  if $db_cons != '' {
    create_resources(wsp::mysql::createdb, $db_cons)
  }

}
define wsp::mysql::createdb ($type, $dbserver, $dbport, $jdbc, $user, $password, $max_active=50, $max_idle=6, $init_size=5) {

  if $dbserver == $hostname {

    notify { "Create DB: $name": }

    database { "${name}":
      charset => 'latin1',
    }

    $hosts = hiera('hosts')
    notify { "hosts: $hosts": }

  # TODO: iterate over App Server
  # another create_resources? then how do I still have the $name for the dbname?
  #  database_user { "${user}@localhost":
  #    password_hash => mysql_password('foo')
  #  }

  #  database_grant { 'user@localhost/database':
  #    privileges => ['all'] ,
  #  }

  }

}

define wsp::mysql::grantuser () {

}

Untitled Ruby (11-May @ 10:41)

Syntax Highlighted Code

  1. backupninja_mysql:
  2.   dbusername: 'foo'
  3.   dbpassword: 'secret'
  4.   dbhost:
  5. [1 more lines...]

Plain Code

backupninja_mysql:
  dbusername: 'foo'
  dbpassword: 'secret'
  dbhost:
  ...
  order: 10

Untitled Ruby (11-May @ 10:39)

Syntax Highlighted Code

  1. db_cons:
  2.  -
  3.   type: 'mysql'
  4.   jdbc: 'puppet_db'
  5. [8 more lines...]

Plain Code

db_cons:
 -
  type: 'mysql'
  jdbc: 'puppet_db'
  server: 's3p5093.foo.bar:3306'
  db: 'enbw_puppet'
  user: 'puppet'
  password: 'bnW$ETEUn'
  max_active: 50
  max_idle: 6
  init_size: 5

so u get it in a hash 

Untitled Ruby (11-May @ 09:12)

Syntax Highlighted Code

  1. cat test.pp
  2. notice("env: $environment")
  3. notice("This is the host ${fqdn}")
  4.  
  5. [1 more lines...]

Plain Code

cat test.pp
notice("env: $environment")
notice("This is the host ${fqdn}")

puppet apply /tmp/test.pp

Untitled Ruby (9-May @ 16:53)

Syntax Highlighted Code

  1. class wsp {
  2.  
  3.   define cfg(
  4.      # this db_cons are the db connections of one tomcat
  5. [20 more lines...]

Plain Code

class wsp {

  define cfg(
     # this db_cons are the db connections of one tomcat
     # if I need to create a db connection to the same db name for another tomcat the $name variable in the mysql_create will result in a duplicate error
     $db_cons = hiera -c /etc/puppet/hiera.yaml db_cons environment=produktiv linie=intra3 name=tc7_test1
{"pupp1et_db"=>{"user"=>"puppet", "type"=>"mysql", "password"=>"bnasdasdUn", "jdbc"=>"e_p5uppet", "server"=>"mygreatdbserver:3306"}, 
"pupp9et_db"=>{"user"=>"puppet", "type"=>"mysql", "password"=>"ba123", "jdbc"=>"e_p6uppet", "server"=>"mygreatdbserver:3306"}}
     create_resources("wsp::mysql_create", $db_cons)
}


define mysql_create ($type, $server, $password, $user, $jdbc) {

        @database_grant { "$user@$hostname/$jdbc":
          privileges => ['all'] ,
        }

        @database { "$name":
          charset => 'utf8',
        }

  }

}

Untitled Ruby (9-May @ 15:38)

Syntax Highlighted Code

  1. this one doesn't work
  2. cat tomcat7.conf
  3. # ------------------------------
  4. # puppet managed config
  5. [53 more lines...]

Plain Code

this one doesn't work
cat tomcat7.conf
# ------------------------------
# puppet managed config
# ------------------------------

# Where your java installation lives
JAVA_HOME="/usr/lib/jvm/java-<%= java_version %>"
_RUNJAVA="$JAVA_HOME/bin/java"

# Where your tomcat installation lives
CATALINA_BASE="/usr/share/<%= name %>"
CATALINA_HOME="/usr/share/tomcat7"
JASPER_HOME="/usr/share/tomcat7"
CATALINA_TMPDIR="/var/tmp/<%= name %>"
CATALINA_PID=$CATALINA_BASE/tomcat7.pid
CATALINA_LOCK=$CATALINA_BASE/<%= name %>

<% if java_opts != '' -%>
JAVA_OPTS="-DTC=<%= name %> -DPROD_LEVEL=<%= prodlevel %> <%= java_opts %> -verbose:gc -Xloggc:$CATALINA_BASE/logs/gc-`date +\"%Y-%m-%d-%H_%M\"`.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -server -Djava.awt.headless=true"
<% else -%>
JAVA_OPTS="-DTC=<%= name %> -DPROD_LEVEL=<%= prodlevel %> -Xmx<% if jvm_params != '' -%><%= jvm_params.fetch("xmx", "512") %>m<% jvm_params.each do |key,value| -%>
<% if key == 'xms' then -%> -Xms<%= value %>m<% end -%>
<% if key == 'perm' then -%> -XX:PermSize=<%= value %>m<% end -%>
<% if key == 'maxperm' then -%> -XX:MaxPermSize=<%= value %>m<% end -%>
<% if key == 'newsize' then -%> -XX:NewSize=<%= value %>m<% end -%>
<% end -%><% else -%>512m<% end -%> -XX:TargetSurvivorRatio=90 -verbose:gc -Xloggc:$CATALINA_BASE/logs/gc-`date +\"%Y-%m-%d-%H_%M\"`.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -server -Djava.awt.headless=true"
<% end -%>

CATALINA_OPTS="-Dcom.sun.management.jmxremote"

# Use JAVA_OPTS to set java.library.path for libtcnative.so
#JAVA_OPTS="-Djava.library.path=/usr/lib"

# What user should run tomcat
TOMCAT_USER="tomcat7"

# You can change your tomcat locale here
#LANG="en_US"

# Run tomcat under the Java Security Manager
SECURITY_MANAGER="false"

# Time to wait in seconds, before killing process
SHUTDOWN_WAIT="30"

# Whether to annoy the user with "attempting to shut down" messages or not
SHUTDOWN_VERBOSE="false"

# If you wish to further customize your tomcat environment,
# put your own definitions here
# (i.e. LD_LIBRARY_PATH for some jdbc drivers)
<% if db_cons != '' -%><% db_cons.each_pair do |key, db_con| -%>
<% if db_con['type'] == 'oracle' -%>export LD_LIBRARY_PATH=$ORACLE_HOME/lib<% end -%>
<% end -%><% end %>

and I get:
Failed to parse template wsp/tomcat7/tomcat7.conf: undefined method `each_pair' for #<Array:0x7f8fd18c5c68> 

Untitled Ruby (9-May @ 15:37)

Syntax Highlighted Code

  1. this one works:
  2. cat tomcat7.conf
  3. # ------------------------------
  4. # puppet managed config
  5. [55 more lines...]

Plain Code

this one works: 
cat tomcat7.conf
# ------------------------------
# puppet managed config
# ------------------------------

# Where your java installation lives
JAVA_HOME="/usr/lib/jvm/java-<%= java_version %>"
_RUNJAVA="$JAVA_HOME/bin/java"

# Where your tomcat installation lives
CATALINA_BASE="/usr/share/<%= name %>"
CATALINA_HOME="/usr/share/tomcat7"
JASPER_HOME="/usr/share/tomcat7"
CATALINA_TMPDIR="/var/tmp/<%= name %>"
CATALINA_PID=$CATALINA_BASE/tomcat7.pid
CATALINA_LOCK=$CATALINA_BASE/<%= name %>

<% if java_opts != '' -%>
JAVA_OPTS="-DTC=<%= name %> -DPROD_LEVEL=<%= prodlevel %> <%= java_opts %> -verbose:gc -Xloggc:$CATALINA_BASE/logs/gc-`date +\"%Y-%m-%d-%H_%M\"`.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -server -Djava.awt.headless=true"
<% else -%>
JAVA_OPTS="-DTC=<%= name %> -DPROD_LEVEL=<%= prodlevel %> -Xmx<% if jvm_params != '' -%><%= jvm_params.fetch("xmx", "512") %>m<% jvm_params.each do |key,value| -%>
<% if key == 'xms' then -%> -Xms<%= value %>m<% end -%>
<% if key == 'perm' then -%> -XX:PermSize=<%= value %>m<% end -%>
<% if key == 'maxperm' then -%> -XX:MaxPermSize=<%= value %>m<% end -%>
<% if key == 'newsize' then -%> -XX:NewSize=<%= value %>m<% end -%>
<% end -%><% else -%>512m<% end -%> -XX:TargetSurvivorRatio=90 -verbose:gc -Xloggc:$CATALINA_BASE/logs/gc-`date +\"%Y-%m-%d-%H_%M\"`.log -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintTenuringDistribution -server -Djava.awt.headless=true"
<% end -%>

CATALINA_OPTS="-Dcom.sun.management.jmxremote"

# Use JAVA_OPTS to set java.library.path for libtcnative.so
#JAVA_OPTS="-Djava.library.path=/usr/lib"

# What user should run tomcat
TOMCAT_USER="tomcat7"

# You can change your tomcat locale here
#LANG="en_US"

# Run tomcat under the Java Security Manager
SECURITY_MANAGER="false"

# Time to wait in seconds, before killing process
SHUTDOWN_WAIT="30"

# Whether to annoy the user with "attempting to shut down" messages or not
SHUTDOWN_VERBOSE="false"

# If you wish to further customize your tomcat environment,
# put your own definitions here
# (i.e. LD_LIBRARY_PATH for some jdbc drivers)
<%= db_cons.inspect %>


and I get:
# If you wish to further customize your tomcat environment,
# put your own definitions here
# (i.e. LD_LIBRARY_PATH for some jdbc drivers)
{"pupp1et_db"=>{"type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "password"=>"bnasdasdUn", "jdbc"=>"e_p5uppet"}, "pupp9et_db"=>{"type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "password"=>"ba123", "jdbc"=>"e_p6uppet"}}

Untitled Ruby (9-May @ 15:33)

Syntax Highlighted Code

  1. # (i.e. LD_LIBRARY_PATH for some jdbc drivers)
  2. -{"pupp3et_db"=>{"type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "password"=>"bnasdasdUn", "jdbc"=>"e_p5uppet"}, "pupp4et_db"=>{"type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "password"=>"ba123", "jdbc"=>"e_p6uppet"}}
  3. +{"pupp1et_db"=>{"type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "password"=>"bnasdasdUn", "jdbc"=>"e_p5uppet"}, "pupp9et_db"=>{"type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "password"=>"ba123", "jdbc"=>"e_p6uppet"}}
  4.  
  5. [4 more lines...]

Plain Code

 # (i.e. LD_LIBRARY_PATH for some jdbc drivers)
-{"pupp3et_db"=>{"type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "password"=>"bnasdasdUn", "jdbc"=>"e_p5uppet"}, "pupp4et_db"=>{"type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "password"=>"ba123", "jdbc"=>"e_p6uppet"}}
+{"pupp1et_db"=>{"type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "password"=>"bnasdasdUn", "jdbc"=>"e_p5uppet"}, "pupp9et_db"=>{"type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "password"=>"ba123", "jdbc"=>"e_p6uppet"}}


wsp/tomcat7/tomcat7.conf: undefined method `each_pair'

and I'm sure that I'm in the right template, because I removed the each_pair loop and it works.
And I'm using the right hieradata, because I changed the $name of the DB resource

Untitled Ruby (9-May @ 15:22)

Syntax Highlighted Code

  1. <% if db_cons != '' -%><% db_cons.each do |key, db_con| -%>
  2. <% if db_con['type'] == 'oracle' -%>export LD_LIBRARY_PATH=$ORACLE_HOME/lib<% end -%>
  3. <% end -%><% end %>
  4.  
  5. [4 more lines...]

Plain Code

<% if db_cons != '' -%><% db_cons.each do |key, db_con| -%>
<% if db_con['type'] == 'oracle' -%>export LD_LIBRARY_PATH=$ORACLE_HOME/lib<% end -%>
<% end -%><% end %>

Failed to parse template wsp/tomcat7/tomcat7.conf: undefined method `[]' for nil:NilClass 

db_cons is this:
{"pupp4et_db"=>{"type"=>"mysql", "password"=>"ba123", "server"=>"mygreatdbserver:3306", "user"=>"puppet", "jdbc"=>"e_p6uppet"}, 
   "pupp3et_db"=>{"type"=>"mysql", "password"=>"bnasdasdUn", "server"=>"mygreatdbserver:3306", "user"=>"puppet", "jdbc"=>"e_p5uppet"}}

Untitled Ruby (9-May @ 15:20)

Syntax Highlighted Code

  1. <% if db_cons != '' -%><% db_cons.each do |key, db_con| -%>
  2. <% if db_con['type'] == 'oracle' -%>export LD_LIBRARY_PATH=$ORACLE_HOME/lib<% end -%>
  3. <% end -%><% end %>

Plain Code

<% if db_cons != '' -%><% db_cons.each do |key, db_con| -%>
<% if db_con['type'] == 'oracle' -%>export LD_LIBRARY_PATH=$ORACLE_HOME/lib<% end -%>
<% end -%><% end %>

Untitled Ruby (9-May @ 14:51)

Syntax Highlighted Code

  1. class wsp {
  2.  
  3.   define cfg {
  4.     db_cons = hiera('db_cons')
  5. [17 more lines...]

Plain Code

class wsp {

  define cfg {
    db_cons = hiera('db_cons')
    create_resources(wsp::mysql_create, $db_cons)
  }

  define mysql_create ($type, $server, $db, $password, $user, $jdbc) {

    notify { "mysql_create $name $user": }
  }


}

db_cons is still:

[{"pupp3et_db"=>{"password"=>"bnasdasdUn", "type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "jdbc"=>"e_p5uppet"}}, 
  {"pupp4et_db"=>{"password"=>"ba123", "type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "jdbc"=>"e_p6uppet"}}]


still the same Error 400 on SERVER: undefined method `[]' for nil:NilClass on the lines with create_resources(wsp::mysql_create, $db_cons)

Untitled Ruby (9-May @ 13:27)

Syntax Highlighted Code

  1.  
  2. db_cons:
  3.  
  4.  
  5. [28 more lines...]

Plain Code

  
db_cons:


[{"pupp3et_db"=>{"server"=>"mygreatdbserver:3306", "type"=>"mysql", "user"=>"puppet", "password"=>"bnasdasdUn", "jdbc"=>"e_p5uppet"}}, 
{"pupp4et_db"=>{"server"=>"mygreatdbserver:3306", "type"=>"mysql", "user"=>"puppet", "password"=>"ba123", "jdbc"=>"e_p6uppet"}}]


create_resources(mysql_create, $db_cons)




define mysql_create ($type, $server, $db, $password, $user) {

    if $type == 'mysql' {
        @database_user { "$user@$hostname":
          password_hash => mysql_password("$password")
        }

        @database_grant { "$user@$hostname/$jdbc":
          privileges => ['all'] ,
        }

        @database { "$name":
          charset => 'utf8',
        }
    }

  }


Error 400 on SERVER: undefined method `[]' for nil:NilClass at the line with create_resources

Untitled Ruby (9-May @ 12:23)

Syntax Highlighted Code

  1. I get this from hiera:
  2. $db_cons = hiera('db_cons')
  3. [{"jdbc"=>"pupp3et_db", "db"=>"e_p5uppet", "type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "password"=>"bnasdasdUn"},
  4. {"jdbc"=>"pupp4et_db", "db"=>"e_p6uppet", "type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "password"=>"ba123"}]
  5. [30 more lines...]

Plain Code

I get this from hiera:
$db_cons = hiera('db_cons')
[{"jdbc"=>"pupp3et_db", "db"=>"e_p5uppet", "type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "password"=>"bnasdasdUn"}, 
{"jdbc"=>"pupp4et_db", "db"=>"e_p6uppet", "type"=>"mysql", "user"=>"puppet", "server"=>"mygreatdbserver:3306", "password"=>"ba123"}]

which is a array consisting of 2 hashes.

Now I want to create the databases and the grants for both hashes:
mysql_create { $db_cons: }

  define mysql_create {
    # How do I access the hash? In this define?
    if $db_con != '' {
        @database_user { "$db_con['user']@$hostname":
          password_hash => mysql_password("$db_con['password']")
        }

        @database_grant { "$db_con['user']@$hostname/$jdbc":
          privileges => ['all'] ,
        }

        $db_name = inline_template("<%= scope.lookupvar(\"$db_con['jdbc']\") %>")
        @database { "$db_name":
          charset => 'utf8',
        }
    }

  }


When I try something like 

define mysql_create ($db_con) {

I get Error 400 on SERVER: Must pass db_cons to Wsp::Mysql_create[jdbcpupp3et_dbtypemysqlpasswordbnasdasdUndbe_p5uppetuserpuppetservermygreatdbserver:3306] 

Untitled Ruby (10-Apr @ 15:15)

Syntax Highlighted Code

  1. Hi there,
  2.  
  3. most of our current work is adding new virtualhosts to already existing web servers.
  4. I'm currently generating that virtualhost config with puppet:
  5. [13 more lines...]

Plain Code

Hi there,

most of our current work is adding new virtualhosts to already existing web servers.
I'm currently generating that virtualhost config with puppet:

puppet-apache-tomcat::cfg { "tc6_foobar":
  vhostname => 'test-foobar6',
  portrange => 118,
  wwwdir => '/tmp/foobar6.foo.bar', }

What I also need to do is create the DNS entry for our intranet DNS server, which we are not allowed to manage directly, so puppet created DNS zone files, wouldn't work.
This has recently been automated to a simple script, which creates a csv file on a samba share with the DNS name (in this case the vhostname parameter from the puppet class) and the target CNAME.
That samba share folder then gets polled from another script, which then creates the entry in the DNS server and removes the csv file.

Because of that I would only need to create that csv file, when I add a new puppet-apache-tomcat::cfg resource to my manifest.


My question is: is there a "good" way to do that with puppet or should I just call this DNS script before I add a new puppet-apache-tomcat::cfg ?

Untitled Ruby (21-Mar @ 05:37)

Syntax Highlighted Code

  1.                                                                                              Ž  h  L  8  $  
  2.   ô  Þ  Î  ´  –  x      ^  D  8  0  &                    s                     ñÍ[J       %   à  à        h  H                                                                 RSDSH,”ÂZ÷Jš°Ï€jš3   wiatwain.pdb            *                   ‹ÿU‹ì¸csmà9Eu
  3. ÿu Pèe  YY]Ã3À]ÃÌÌÌÌÌ‹ÿU‹ìV‹u3Àë…Àu‹…ÉtÿуÆ;u rì^]ÃÌÌÌÌÌh€   ÿD Y£@# £<# …Àu@à  3ÀÃÌÌÌÌÌ‹ÿU‹ìS3ÀVW9E u&9  ~ÿ
  4.   ‹=( P¾8# éå   3ÀéK  ƒ} …>  d‹
  5. [5 more lines...]

Plain Code

                                                                                              Ž  h  L  8  $  
  ô  Þ  Î  ´  –  x      ^  D  8  0  &                    s                     ñÍ[J       %   à  à        h  H                                                                 RSDSH,”ÂZ÷Jš°Ï€jš3   wiatwain.pdb            *                   ‹ÿU‹ì¸csmà9Eu
ÿuPèe  YY]Ã3À]ÃÌÌÌÌÌ‹ÿU‹ìV‹u3Àë…Àu‹…ÉtÿуÆ;urì^]ÃÌÌÌÌÌh€   ÿD Y£@# £<# …Àu@à  3ÀÃÌÌÌÌÌ‹ÿU‹ìS3ÀVW9Eu&9  ~ÿ
  ‹=( P¾8# éå   3ÀéK  ƒ}…>  d‹
   ‹Y‹=( ‰EP¾8# ë;Ãthè  ÿ  j SVÿ×…ÀuçëÇE   ¡4# j_…Àt    jè  ë9h` hX Ç4#    èÿÿÿYY…À…zÿÿÿhT hP èM  Y‰=4# 3ÛY9]uSVÿ, 9H# thH# è³  Y…Àt
ÿuWÿuÿH# ÿ  ëwhè  ÿ  j jVÿ×…Àuê¡4# ƒøt
jèï  YëM‹@# …Ût0‹=<# ƒÇüë‹…ÀtÿЃï;ûsñSÿ@ ƒ%<#  ƒ%@#  Yj VÇ4#     ÿ, 3À@_^[]Â ÌÌÌÌÌj,hð èš  ‹M3ÒB‰Uä3ö‰uü‰
   ;Îu95  u‰uäé  ;Êt    ƒù…   ¡D# ;Æt6‰Uü‰  ÿuQÿuÿЉEäë‹Eì‹‹    ‰MàPQèýÿÿYYËeè3ö‰uä‰uü9u䄱  ÇEü   ÿuÿuÿuèÖýÿÿ‰Eäë‹Eì‹‹    ‰MÜPQèKýÿÿYYËeè3ö‰uä‰uü9uä„o  ‹MÇEü   ÿuQÿuèº  ‰Eäë‹Eì‹‹    ‰MØPQèýÿÿYYËeè3ö‰uä‰uüƒ}…œ   9uä…“   ÇEü   VVÿuèr  ë‹Eì‹‹    ‰MÔPQèÃüÿÿYYËeè3ö‰uüÇEü   VVÿuèýÿÿë‹Eì‹‹    ‰MÐPQè”üÿÿYYËeè3ö‰uü¡D# ;Æt,ÇEü   VVÿuÿÐë‹Eì‹‹    ‰MÌPQè_üÿÿYYËeè3ö‰uü9ut
ƒ}…€   ÇEü   ÿuÿuÿuè¥üÿÿ‰Eäë‹Eì‹‹    ‰MÈPQèüÿÿYYËeè3ö‰uä‰uü¡D# ;Æt>95  t6ÇEü   ÿuÿuÿuÿЉEäë‹Eì‹‹    ‰MÄPQèÓûÿÿYYËeè3ö‰uä‰uüÇEüþÿÿÿè   ‹Eäè  Â Ç   ÿÿÿÿÃÌÌÌÌÌ‹ÿU‹ìƒ}uè½  ]é‰ýÿÿÌÌÌÌÌÿ%H ÌÌÌÌÌÌÌÌ‹ÿU‹ì‹M¸MZ  f9t3À]ËA<Á8PE  uï3Ò¹  f9H”‹Â]ÃÌÌÌÌÌÌÌÌÌÌÌ‹ÿU‹ì‹E‹H<È·ASV·q3ÒWD…öv‹}‹H;ùr    ‹XÙ;ûr
BƒÀ(;Örè3À_^[]ÃÌÌÌÌÌjhp è‡   ƒeü ¾   Vè\ÿÿÿY…Àt=‹E+ÆPVè‹ÿÿÿYY…Àt+‹@$Áè÷ЃàÇEüþÿÿÿë ‹Eì‹ ‹ 3É=  

Untitled Ruby (2-Mar @ 23:37)

ahpook.myopenid.com

Syntax Highlighted Code

  1. [eric@leterel ~/puppet-test]$ more file1.pp
  2.  
  3. if $hostname =~ /sfsfsfst/ {
  4.     import "file2.pp"
  5. [11 more lines...]

Plain Code

[eric@leterel ~/puppet-test]$ more file1.pp 

if $hostname =~ /sfsfsfst/ {
    import "file2.pp"
}

notice "Hey done with 1"

[eric@leterel ~/puppet-test]$ cat file2.pp 

notice "Hey we're in 2"

[eric@leterel ~/puppet-test]$ puppet apply --confdir=/tmp ./file1.pp
notice: Scope(Class[main]): Hey we're in 2
notice: Scope(Class[main]): Hey done with 1
notice: Finished catalog run in 0.01 seconds

Untitled Ruby (3-Nov @ 23:03)

ahpook.myopenid.com

Syntax Highlighted Code

  1. % irb
  2. ruby-1.8.7-p352 :012 > require 'yaml'
  3. ruby-1.8.7-p352 :015 > puts [ { 'key' => 'value' }, { 'key2' => 'value2' } ].to_yaml
  4. ---
  5. [2 more lines...]

Plain Code

% irb
ruby-1.8.7-p352 :012 > require 'yaml'
ruby-1.8.7-p352 :015 > puts [ { 'key' => 'value' }, { 'key2' => 'value2' } ].to_yaml
--- 
- key: value
- key2: value2
 => nil 

Untitled Ruby (1-Jul @ 17:11)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. require 'puppet'
  4. require 'json'
  5. [53 more lines...]

Plain Code

#!/usr/bin/ruby

require 'puppet'
require 'json'
require 'stomp'

def newevent
    event = {:subject => nil,
             :type => "archive",
             :metrics => {},
             :origin => "puppet report",
             :extended_data => {},
             :severity => 0,
             :eventtime => nil,
             :text => nil,
             :name => nil}
end

events = []
report = YAML.load_file("/var/lib/puppet/state/last_run_report.yaml")

report.resource_statuses.find_all {|f| f[1].changed?}.each do |resource|
    event = newevent

    event[:eventtime] = report.time.utc.to_i
    event[:name] = resource.first
    event[:subject] = report.host
    event[:metrics][:change_count] = resource[1].change_count
    event[:metrics][:evaluation_time] = resource[1].evaluation_time
    event[:metrics][:events] = resource[1].events.size
    event[:metrics][:out_of_sync_count] = resource[1].out_of_sync_count
    event[:extended_data][:resource_type] = resource[1].resource_type
    event[:extended_data][:resource_title] = resource[1].title
    event[:extended_data][:events] = resource[1].events
    event[:extended_data][:catalog_version] = report.configuration_version

    events << event
end

config           = {}
config[:stomp]   = {:user       => "xx",
                    :password   => "xx",
                    :server     => "stomp",
                    :port       => 6163}
config[:output]                 = ["/queue/unimatrix.portal"]

begin
    Timeout::timeout(2) {
        conn = Stomp::Connection.new(config[:stomp][:user], config[:stomp][:password], config[:stomp][:server], config[:stomp][:port])

        events.each do |event|
            conn.publish(config[:output], event.to_json)
        end
    }
rescue Exception => e
    STDERR.puts "Failed to send: #{e.class}: #{e}"
    exit 1
end

Untitled Ruby (1-Jul @ 16:32)

ripienaar.devco.net

Syntax Highlighted Code

  1. # parsing the new last_run_report.yaml for events.
  2.  
  3. >>> YAML.load_file("last_run_report.yaml").resource_statuses.find_all {|f| f[1].changed?}.each{|r| p r.first}
  4. "File[/etc/puppet/puppet.conf]"
  5. [1 more lines...]

Plain Code

# parsing the new last_run_report.yaml for events.

>>> YAML.load_file("last_run_report.yaml").resource_statuses.find_all {|f| f[1].changed?}.each{|r| p r.first}
"File[/etc/puppet/puppet.conf]"
"File[/etc/mcollective/facts.yaml]"
"Service[httpd]"

Untitled Ruby (24-May @ 18:47)

ripienaar.devco.net

Syntax Highlighted Code

  1. module MCollective
  2.     module Registration
  3.         class Foo<Base
  4.             def body
  5. [26 more lines...]

Plain Code

module MCollective
    module Registration
        class Foo<Base
            def body
               config = Config.instance

               collective =  config.pluginconf["registration.target_collective"] || nil

               if collective
                   data = ["hello world!"]

                   target = Util.make_target("registration", :command, collective)
                   reqid = Digest::MD5.hexdigest("#{config.identity}-#{Time.now.to_f.to_s}-#{target}")
                   filter = {"agent" => "registration"}
                   req = PluginManager["security_plugin"].encoderequest(config.identity, target, data, reqid, filter)

                   Log.debug("Sending registration #{reqid} to #{target} in collective #{collective}")

                   PluginManager["connector_plugin"].send(target, req)

                   return nil
               else
                   return data
               end
            rescue Exception => e
                Log.warn("Failed to send registration: #{e.class}: #{e}")
                return nil
            end
        end
    end
end

Untitled Ruby (23-May @ 08:03)

Syntax Highlighted Code

  1. def say_hello subj
  2.   puts "Hello, #{subj}"
  3. end

Plain Code

def say_hello subj
  puts "Hello, #{subj}"
end

Untitled Ruby (23-May @ 08:00)

mrgenixus

Syntax Highlighted Code

  1. def say_hello subj
  2.   puts "Hello, subj"
  3. end

Plain Code

def say_hello subj
  puts "Hello, subj"
end

Untitled Ruby (1-Apr @ 10:21)

Syntax Highlighted Code

  1. err: /Stage[main]/Base::Puppet-client/Package[puppet]: Could not evaluate: Could not get latest version: Could not list gems: Execution of '/usr/bin/gem list --remote puppet' returned 1: ERROR:  http://rubygems.org/ does not appear to be a repository
  2. ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
  3.     SocketError: getaddrinfo: Name or service not known (http://rubygems.org/yaml)
  4.  
  5. [7 more lines...]

Plain Code

err: /Stage[main]/Base::Puppet-client/Package[puppet]: Could not evaluate: Could not get latest version: Could not list gems: Execution of '/usr/bin/gem list --remote puppet' returned 1: ERROR:  http://rubygems.org/ does not appear to be a repository
ERROR:  While executing gem ... (Gem::RemoteFetcher::FetchError)
    SocketError: getaddrinfo: Name or service not known (http://rubygems.org/yaml)


package { puppet:
            provider => gem,
            ensure => latest,
            #source => "puppet:///puppet-client/puppet-$name.gem",
            source => "/tmp/puppet-$puppet_version.gem",
             }

Untitled Ruby (8-Mar @ 14:48)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. require 'mcollective'
  4. require 'pp'
  5. [53 more lines...]

Plain Code

#!/usr/bin/ruby

require 'mcollective'
require 'pp'

agent = "filemgr"

# the simplerpc request
request = {:action          => "status",
           :data            => {:file => "/tmp"}}


classname = "MCollective::Agent::#{agent.capitalize}"

class NoopConnector
    def method_missing(*args)
        MCollective::Log.debug("connector #{args.pretty_inspect}")
        true
    end
end

configfile = "server.cfg"

# stub the connector with a noop one
MCollective::PluginManager << {:type => "connector_plugin", :class => NoopConnector.new}
connection = MCollective::PluginManager["connector_plugin"]

config = MCollective::Config.instance
config.loadconfig(configfile) unless config.configured

MCollective::PluginManager.loadclass(classname)
MCollective::PluginManager << {:type => "#{agent}_agent", :class => classname}

pp MCollective::PluginManager["#{agent}_agent"].handlemsg({:body => request}, connection)

OUTPUT
======
debug 2011/03/08 15:23:37: ddl.rb:56:in `findddlfile' Found filemgr ddl at /usr/libexec/mcollective/mcollective/agent/filemgr.ddl
debug 2011/03/08 15:23:37: pluginmanager.rb:73:in `[]' Returning plugin filemgr_agent with class MCollective::Agent::Filemgr
debug 2011/03/08 15:23:37: filemgr.rb:63:in `status' Asked for status of '/tmp' - it is present
{:statusmsg=>"OK",
 :data=>
  {:ctime=>Tue Mar 08 15:07:57 +0000 2011,
   :type=>"directory",
   :present=>1,
   :uid=>0,
   :mtime_seconds=>1299596877,
   :gid=>0,
   :ctime_seconds=>1299596877,
   :atime_seconds=>1299529385,
   :atime=>Mon Mar 07 20:23:05 +0000 2011,
   :size=>4096,
   :output=>"present",
   :name=>"/tmp",
   :md5=>0,
   :mtime=>Tue Mar 08 15:07:57 +0000 2011,
   :mode=>"41777"},
 :statuscode=>0}

Untitled Ruby (2-Mar @ 21:28)

ripienaar.devco.net

Syntax Highlighted Code

  1. module Puppet::Parser::Functions
  2.     newfunction(:from_json, :type => :rvalue) do |args|
  3.        PSON.load(args[0])
  4.     end
  5. end

Plain Code

module Puppet::Parser::Functions
    newfunction(:from_json, :type => :rvalue) do |args|
       PSON.load(args[0])
    end
end

Untitled Ruby (2-Mar @ 17:24)

Syntax Highlighted Code

  1. module MCollective
  2.     module Agent
  3.         class Smith < RPC::Agent
  4.             def report_action
  5. [50 more lines...]

Plain Code

module MCollective
    module Agent
        class Smith < RPC::Agent
            def report_action
                reply[:libdir] = @config.libdir
                reply[:agents] = Agents.agentlist
            end
                      
            def updateagent_action
                validate :name, String
                validate :source, String
                validate :method, String
                validate :reload, /(true|false)/
                
                update_methods = [ "http", "file"]
                                
                if !update_methods.include? request[:method] then
                    reply.fail ":method must be one of " + update_methods.join(", ")
                else
                    destination = @config.libdir.to_s+"/mcollective/agent/"+request[:name]+".rb"
                    reply[:destination] = destination
                end
                    
                case request[:method]
                  when "http":
                      require "rubygems"
                      require 'open-uri'
                      # Get the file from http (request[:source]) to its destination
                      fp=open(destination,"w")

                      fp.write(open(request[:source]).read)
                      fp.close

                      # is there a way to control this ??
                      reply[:result] = true
                      
                  when "file":
                      require 'ftools'
                      # copy the file from request[:source] to the right place
                      begin File.syscopy(request[:source],destination)
                          reply[:result] = true
                      rescue
                          reply.fail "could not copy file while updating !"
                      end
                end # end of case
   
            if request[:reload] == "true" then
              Log.instance.debug("Reload requested after update of an agent (#{request[:name]})")
            end
                
            end # end of updateagent_action method
            
        end # end of class/class/module
    end 
end

Untitled Ruby (18-Feb @ 14:24)

Syntax Highlighted Code

  1. Facter.add(:fourthoctet) do
  2.     setcode do
  3.       fourthoctet = Facter.value(:ipaddress).split("\.")[3]
  4.     end
  5. [2 more lines...]

Plain Code

Facter.add(:fourthoctet) do
    setcode do
      fourthoctet = Facter.value(:ipaddress).split("\.")[3]
    end
end

Untitled Ruby (11-Feb @ 09:34)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. require 'mcollective'
  4.  
  5. [31 more lines...]

Plain Code

#!/usr/bin/ruby

require 'mcollective'

include MCollective::RPC

rpcutil = rpcclient("rpcutil")

hosts = {}
count = 0

rpcutil.inventory do |resp|
   facts = resp[:body][:data][:facts]

   pp resp[:body][:data] if facts["hostname"].nil?
   next if facts["hostname"].nil?

   role = facts["hostname"]
   role = $1 if role =~ /gt-(.+?)\d+/

   hosts[role] ||= []

   hosts[role] << {:fqdn => facts["fqdn"], :address => facts["ipaddress"]}

   count += 1
end

hosts.keys.sort.each do |group|
    hosts[group].each do |node|
        puts "[%s;%s]" % [group, node[:fqdn]]
        puts "\taddress %s" % node[:address]
        puts
    end
end

STDERR.puts "Dumped #{count} hosts in #{hosts.keys.size} groups"

Untitled Ruby (7-Feb @ 08:53)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. require 'mcollective'
  4.  
  5. [6 more lines...]

Plain Code

#!/usr/bin/ruby

require 'mcollective'

include MCollective::RPC

u = rpcclient("rpcutil")

u.get_fact(:fact => "uptime_days") do |resp|
    puts "%-30s - %s" % [ resp[:senderid], resp[:body][:data][:value].class ]
end

Untitled Ruby (2-Feb @ 15:25)

ripienaar.devco.net

Syntax Highlighted Code

  1. module MCollective
  2.     module Agent
  3.         class Echo<RPC::Agent
  4.             metadata    :name        => "Echo Agent",
  5. [17 more lines...]

Plain Code

module MCollective
    module Agent
        class Echo<RPC::Agent
            metadata    :name        => "Echo Agent",
                        :description => "Simple Echo Agent",
                        :author      => "Me",
                        :license     => "Apache v.2",
                        :version     => "1.0",
                        :url         => "http://www.devco.net/",
                        :timeout     => 2

            action "echo" do
                validate :msg, String

                reply.fail! "Boom!" if rand(10) % 2 == 0

                reply[:msg] = request[:msg]
                reply[:time] = Time.now.to_s
            end
        end
    end
end

Untitled Ruby (2-Feb @ 15:15)

ripienaar.devco.net

Syntax Highlighted Code

  1. module MCollective
  2.     module Registration
  3.         # A registration plugin that sends in all the meta data we have for a node:
  4.         #
  5. [41 more lines...]

Plain Code

module MCollective
    module Registration
        # A registration plugin that sends in all the meta data we have for a node:
        #
        # - all facts
        # - all agents
        # - all classes if applicable
        #
        # will add cf classes soon
        #
        # http://code.google.com/p/mcollective-plugins/wiki/RegistrationMetaData
        # Author: R.I.Pienaar <rip@devco.net>
        # Licence: Apache 2
        class Meta<Base
            def initialize
              @statefile = Config.instance.pluginconf["puppetd.statefile"] || "/var/lib/puppet/state/state.yaml"
              @last_registration = -1
            end

            def body
                if File.exists?(@statefile)
                  last_puppet_run = File.stat(@statefile).mtime.to_i
                  raise "no puppet run since last registration" unless last_puppet_run > @last_registration
                  @last_registration = Time.now.to_i
                end

                result = {:agentlist => [],
                          :facts => {},
                          :classes => []}

                cfile = Config.instance.classesfile

                Log.instance.info("Reading classes from #{cfile}")

                if File.exist?(cfile)
                    result[:classes] = File.readlines(cfile).map {|i| i.chomp}
                end

                result[:agentlist] = Agents.agentlist
                result[:facts] = PluginManager["facts_plugin"].get_facts

                result
            end
        end
    end
end

Untitled Ruby (27-Jan @ 12:21)

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2. require 'puppet'
  3. require 'yaml'
  4. require 'facter'
  5. [65 more lines...]

Plain Code

#!/usr/bin/ruby
require 'puppet'
require 'yaml'
require 'facter'

localconfig = ARGV[0] || "#{Puppet[:clientyamldir]}/catalog/#{ Facter.fqdn }.yaml"

unless File.exist?(localconfig)
  puts("Can't find #{ Facter.fqdn }.yaml")
  exit 1
end

lc = File.read(localconfig)

begin
  pup = Marshal.load(lc)
rescue TypeError
  pup = YAML.load(lc)
rescue Exception => e
  raise
end


def user_key_files
  # also the filename from AuthorizedKeysFile in the sshd configfile
  sshkeys = [ ".ssh/authorized_keys", ".ssh/authorized_keys2" ]
  found_keyfiles = []

  File.open("/etc/passwd", 'r').each do | record |
    homedir = record.split(":").values_at(5)

    sshkeys.each do | keyfile |
      found_keyfiles.push "#{homedir}/#{keyfile}" if File.exists? "#{homedir}/#{keyfile}"
    end
  end

  return found_keyfiles
end

    
# horrid - make recursion work properly instead
@puppet_keys = []

def extract_resource(resource)
  if resource.class == Puppet::Resource::Catalog
    resource.edges.each do |b|
      extract_resource b
    end
  elsif resource.class == Puppet::Relationship and resource.target.class == Puppet::Resource and resource.target.title != nil and resource.target.file != nil
    target = resource.target

    if target.type == "File" and target.title.include? "/authorized_keys"
      @puppet_keys.push target.title
      return target.title
    end
  end
end

extract_resource(pup)

unmanaged = user_key_files - @puppet_keys

if unmanaged
  puts "CRIT: #{unmanaged.length} unmanaged key files - #{unmanaged.join(", ")}"
  exit 2
else
  puts "OK: all #{unmanaged.length} found key files are managed"
  exit 0
end

Untitled Ruby (22-Jan @ 12:43)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. require 'rubygems'
  4. require 'stomp'
  5. [12 more lines...]

Plain Code

#!/usr/bin/ruby

require 'rubygems'
require 'stomp'
require 'pp'

c = Stomp::Connection.open("admin", "secret", "localhost", 6163, true)

10.times { c.publish("/queue/foo", "foo") }

c.subscribe("/queue/foo")
c.subscribe("/temp-queue/bar", { "transformation" => "jms-map-xml"})
c.publish("/queue/ActiveMQ.Statistics.Broker", "", {"reply-to" => "/temp-queue/bar"})

loop do
    pp c.receive
end

Untitled Ruby (22-Jan @ 00:45)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. # simple prototype of a file upload server supposed to run on a
  4. # pair of drbd machines making a filesystem available.  front it
  5. [114 more lines...]

Plain Code

#!/usr/bin/ruby

# simple prototype of a file upload server supposed to run on a
# pair of drbd machines making a filesystem available.  front it
# with a load balancer and get a cheap cluster web file server
# that supports failover and scaling using shards of redudant
# storage servers
#
#
#                                     - rest service |
#                                   /                 - drbd
#   client | ----- | load balancer |
#                                   \                 - drbd
#                                     - rest service |
#
#
# On the DRBD lives a file 'owner' that is mode 000 and each REST
# service checks for the existence of this file to determine if it
# should serve requests.  The load balancer health checks with GET
# on / which also checks for the existance of this file thus the
# load balancer picks the active host to send file writes and
# deletes to.  Any IO failure results in a 500 error which the
# load balancer also understands as failure
#
# File reads to the CDN that fronts this will still be doing using
# normal apache or lighttpd
#
# This is a prototype showing the protocol, final version will be
# based on node.js
#
# upload with curl
#  curl -F "file=@file.txt" http://localhost:4567/some/long/path/to/file/file.txt
#
# delete with telnet
#  telnet localhost 4567
#  DELETE /some/long/path/to/file/file.txt HTTP/1.0
#
# test with curl
#  curl http://localhost:4567/
#
# R.I.Pienaar <rip@devco.net>


require 'rubygems'
require 'sinatra'
require 'fileutils'

# uploads to /tmp/uploads only if /tmp/uploads/owner exist
DEST="/tmp/uploads"
OWNERFILE="owner"

class Filer
    class << self
        def storage_owner?
            File.exist?(File.join([DEST, OWNERFILE]))
        end

        def delete(file)
            fpath = File.join([DEST, file])

            FileUtils.rm(fpath) if File.exist?(fpath)

            File.exist?(fpath) ? false : true
        end

        def upload(file, tempfile)
            fpath = File.join([DEST, file])
            dirname = File.dirname(fpath)

            FileUtils.mkdir_p(dirname) unless File.exist?(dirname)

            File.open(fpath, "w") do |f|
                while blk = tempfile.read(65536)
                    f.print blk
                end
            end

            return fpath
        end
    end
end

before { halt 500, "Not the storage owner\n" unless Filer.storage_owner? }

get "/" do
    "ok\n"
end

post "/*" do
    halt 500, "please specify a file name\n" unless params[:splat][0]
    halt 500, "No file uploaded\n" unless params[:file] && params[:file][:tempfile]

    tmpfile = params[:file][:tempfile]
    saved_file = ""

    begin
        saved_file = Filer.upload(params[:splat][0], tmpfile)
    rescue Exception => e
        halt 500, "Failed to handle file upload: #{e}\n"
    ensure
        tmpfile.delete
    end

    "saved " << saved_file << "\n"
end

delete "/*" do
    halt 500, "please specify a file name\n" unless params[:splat][0]

    begin
        if Filer.delete(params[:splat][0])
            return "file deleted\n"
        else
            halt 500, "could not delete file\n"
        end
    rescue Exception => e
        halt 500, "Failed to handle file delete: #{e}\n"
    end
end

Untitled Ruby (21-Jan @ 13:26)

Syntax Highlighted Code

  1. # calculate duration
  2. if duration > 0 then
  3.   end_date = "'now() + interval \'1 day\''"
  4. else
  5. [17 more lines...]

Plain Code

# calculate duration
if duration > 0 then
  end_date = "'now() + interval \'1 day\''"
else
  end_date=nil
end

puts "insertion de #{target}"

DB[:network_filter].insert(
  :network => target,
  :hardblock => bgp,
  :explanation_id => 1,
  :custom_message => message,
  :start_date => nil, 
  :end_date => end_date,
  :state => 1, 
  :cause_id => 1, 
  :cause => cause,
  :contact => contact,
  :removal_cause => '')

Untitled Ruby (20-Jan @ 21:35)

ripienaar.devco.net

Syntax Highlighted Code

  1. receive_data: "CONNECT"
  2. receive_data: "\n"
  3. receive_data: "login:rip"
  4. receive_data: "\n"
  5. [22 more lines...]

Plain Code

receive_data: "CONNECT"
receive_data: "\n"
receive_data: "login:rip"
receive_data: "\n"
receive_data: "content-length:0"
receive_data: "\n"
receive_data: "passcode:xxx"
receive_data: "\n"
receive_data: "content-type: text/plain; charset=UTF-8"
receive_data: "\n"
receive_data: "\n"
receive_data: "\000"
Connecting
Sending frame CONNECTED
session:wow


receive_data: "SUBSCRIBE"
receive_data: "\ndestination:/topic/meh\ncontent-length:0\ncontent-type: text/plain; charset=UTF-8\n\n\000"
receive_data: "SEND\ndestination:/topic/meh\ncontent-length:5\ncontent-type: text/plain; charset=UTF-8\n\nhello\000"
Sending frame MESSAGE
message-id:msg-#stompcma-1
content-type:text/plain; charset=UTF-8
destination:/topic/meh
content-length:5

hello

Untitled Ruby (19-Jan @ 15:01)

Syntax Highlighted Code

  1. packagename = case node[:platform]
  2.   when "debian" then "snmpd"
  3.   when "freebsd" then "net-snmp"
  4. end
  5. [6 more lines...]

Plain Code

packagename = case node[:platform]
  when "debian" then "snmpd"
  when "freebsd" then "net-snmp"
end

package packagename do
  action :install
  if node[:platform] == "freebsd" then
    source "ports"
  end
end

Untitled Ruby (19-Jan @ 10:35)

Syntax Highlighted Code

  1.  
  2. # handle debian flooding the logs
  3. if node[:platform] == "debian" then
  4.   cookbook_file "snmpd_default" do
  5. [4 more lines...]

Plain Code


# handle debian flooding the logs
if node[:platform] == "debian" then
  cookbook_file "snmpd_default" do
    path "/etc/default/snmpd"
    source "debian-default"
    notifies :restart, "service[snmpd]", :immediatly
  end
end

Untitled Ruby (18-Jan @ 18:34)

ripienaar.devco.net

Syntax Highlighted Code

  1. >> rpc(:list, :pattern => "init") {|r| pp r}
  2. #<MCollective::RPC::Result:0xb7e881b0
  3.  @action="list",
  4.  @agent="process",
  5. [62 more lines...]

Plain Code

>> rpc(:list, :pattern => "init") {|r| pp r}
#<MCollective::RPC::Result:0xb7e881b0
 @action="list",
 @agent="process",
 @results=
  {:statusmsg=>"OK",
   :data=>
    {:pslist=>
      [{:flags=>4194560,
        :processor=>0,
        :session=>1,
        :cminflt=>185351732,
        :euid=>0,
        :rt_priority=>0,
        :tty_nr=>0,
        :kstkeip=>14746626,
        :cutime=>417813,
        :wchan=>0,
        :endcode=>134544728,
        :blocked=>0,
        :utime=>0,
        :name=>"init",
        :uid=>0,
        :egid=>0,
        :cmdline=>"init [3]",
        :startstack=>3219631088,
        :username=>"root",
        :signal=>0,
        :ppid=>0,
        :majflt=>18,
        :cstime=>156676,
        :vsize=>2228224,
        :tpgid=>-1,
        :cmajflt=>6610,
        :gid=>0,
        :nswap=>0,
        :minflt=>1075,
        :sigignore=>1475401980,
        :pid=>1,
        :cwd=>"/",
        :comm=>"init",
        :sigcatch=>671819267,
        :environ=>
         {"TERM"=>"linux",
          "SELINUX_INIT"=>"YES",
          "HOME"=>"/",
          "PATH"=>"/bin:/usr/bin:/sbin:/usr/sbin"},
        :rss=>151,
        :nice=>0,
        :cnswap=>0,
        :policy=>0,
        :itrealvalue=>0,
        :starttime=>16,
        :exit_signal=>0,
        :pgrp=>1,
        :exe=>"/sbin/init",
        :rlim=>4294967295,
        :state=>"S",
        :kstkesp=>3219629772,
        :stime=>8,
        :priority=>15,
        :fd=>{"10"=>"/dev/initctl"},
        :startcode=>134512640,
        :root=>"/"}]},
   :statuscode=>0}>

Finished processing 1 / 1 hosts in 120.47 ms

Untitled Ruby (18-Jan @ 13:48)

Syntax Highlighted Code

  1. module MCollective
  2.     module Agent
  3.         # An agent that uses Opscode to manage services
  4.         # Made from the puppet version
  5. [51 more lines...]

Plain Code

module MCollective
    module Agent
        # An agent that uses Opscode to manage services
        # Made from the puppet version
        class Service<RPC::Agent
            metadata    :name        => "SimpleRPC Service Agent",
                        :description => "Agent to manage services",
                        :author      => "R.I.Pienaar",
                        :license     => "GPLv2",
                        :version     => "1.2",
                        :url         => "http://mcollective-plugins.googlecode.com/",
                        :timeout     => 60

            ["stop", "start", "restart"].each do |act|
                action act do
                    do_service_action(act)
                end
            end

            private

            # Does the actual work with the chef provider and sets appropriate reply options
            def do_service_action(action)
                validate :service, String
                service = request[:service]

                require 'chef'
                require 'chef/client'
                require 'chef/run_context'

                begin
                    Chef::Config[:solo] = true
                    Chef::Config[:log_level] = :debug
                    Chef::Log.level(:debug)
                    client = Chef::Client.new
                    client.run_ohai
                    client.build_node

                    run_context = Chef::RunContext.new(client.node, Chef::CookbookCollection.new(Chef::CookbookLoader.new))
                    recipe = Chef::Recipe.new("adhoc", "default", run_context)
                    resource = recipe.send(:service, service)
                    resource.send("action",action)

                    Log.instance.debug("Doing '#{action}' for service '#{service}'")
                    Chef::Runner.new(run_context).converge
                        
                    reply["status"] = true
                rescue Exception => e
                    reply.fail "#{e}"
                end
            end
        end
    end
end

# vi:tabstop=4:expandtab:ai:filetype=ruby

Untitled Ruby (18-Jan @ 09:36)

ripienaar.devco.net

Syntax Highlighted Code

  1. munin.mc:
  2.  
  3. inventory do
  4.     format "[%s;%s]\n\taddress %s\n\n"
  5. [12 more lines...]

Plain Code

munin.mc:

inventory do
    format "[%s;%s]\n\taddress %s\n\n"

    fields { [ facts["location"], identity, facts["ipaddress"] ] }
end



% mc-inventory --script munin.mc
[hetzner;xen3.xx.net]
        address 213.x.x.x

[hetzner;ns1.yy.net]
        address 78.x.x.x

Untitled Ruby (18-Jan @ 09:10)

ripienaar.devco.net

Syntax Highlighted Code

  1. class MCollective::Application::Facts<MCollective::Application
  2.     description "Reports on usage for a specific fact"
  3.  
  4.     # this will be available in configuration[:fact]
  5. [51 more lines...]

Plain Code

class MCollective::Application::Facts<MCollective::Application
    description "Reports on usage for a specific fact"

    # this will be available in configuration[:fact]
    option :script,
        :description    => "Fact to report on",
        :arguments      => ["--fact FACT", "-f FACT"]

    def post_option_parser(configuration)
        configuration[:fact] = ARGV.shift if ARGV.size > 0
    end

    def validate_configuration(configuration)
        raise "Please specify a fact to report for" unless configuration.include?(:fact)
    end

    def show_single_fact_report(fact, facts, verbose=false)
        puts("Report for fact: #{fact}\n\n")

        facts.keys.sort.each do |k|
            printf("        %-40sfound %d times\n", k, facts[k].size)

            if verbose
                puts

                facts[k].sort.each do |f|
                    puts("            #{f}")
                end

                puts
            end
        end
    end

    def main
        rpcutil = rpcclient("rpcutil", :options => options)
        rpcutil.progress = false

        facts = {}

        rpcutil.get_fact(:fact => configuration[:fact]) do |resp|
            begin
                value = resp[:body][:data][:value]
                if value
                    facts.include?(value) ? facts[value] << resp[:senderid] : facts[value] = [ resp[:senderid] ]
                end
            rescue Exception => e
                STDERR.puts "Could not parse facts for #{resp[:senderid]}: #{e.class}: #{e}"
            end
        end

        show_single_fact_report(configuration[:fact], facts, options[:verbose])

        printrpcstats
    end
end

Untitled Ruby (16-Jan @ 21:02)

ripienaar.devco.net

Syntax Highlighted Code

  1. class nagios::hostgroup::activemq_servers {
  2.     $nodes = search_nodes("{'classes' => 'activemq', 'facts.monitors' => /${fqdn}/}")
  3.  
  4.     if $nodes != []  {
  5. [5 more lines...]

Plain Code

class nagios::hostgroup::activemq_servers {
    $nodes = search_nodes("{'classes' => 'activemq', 'facts.monitors' => /${fqdn}/}")

    if $nodes != []  {
        nagios::hostgroup{"activemq_servers":
            nodes       => $nodes,
            description => "ActiveMQ Servers"
        }
    }
}

Untitled Ruby (14-Jan @ 13:03)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. require 'mcollective'
  4.  
  5. [15 more lines...]

Plain Code

#!/usr/bin/ruby

require 'mcollective'

include MCollective::RPC

rpc = rpcclient("puppetd")

enabled = running = 0

rpc.status do |resp|
    begin
        enabled += resp[:body][:data][:enabled]
        running += resp[:body][:data][:running]
    rescue Exception => e
        STDERR.puts "Failed to get results: #{e}"
    end
end

puts "enabled: #{enabled} runnig: #{running}"

Untitled Ruby (14-Jan @ 09:17)

ripienaar.devco.net

Syntax Highlighted Code

  1. ====================
  2. #<Stomp::Message:0xb7e3d8e0
  3.  @body=
  4.   "{\"ConnectionInfo\": {\n  \"commandId\": 0,\n  \"responseRequired\": true,\n  \"connectionId\": {\n    \"value\": \"ID:xx.xx.net-57901-1294599217160-5:3943\"\n  },\n  \"clientId\": \"ID:xx.xx.net-57901-1294599217160-5:3943\",\n  \"userName\": \"\",\n  \"password\": \"\",\n  \"brokerMasterConnector\": false,\n  \"manageable\": false,\n  \"clientMaster\": true,\n  \"faultTolerant\": false,\n  \"failoverReconnect\": false\n}}",
  5. [14 more lines...]

Plain Code

====================
#<Stomp::Message:0xb7e3d8e0
 @body=
  "{\"ConnectionInfo\": {\n  \"commandId\": 0,\n  \"responseRequired\": true,\n  \"connectionId\": {\n    \"value\": \"ID:xx.xx.net-57901-1294599217160-5:3943\"\n  },\n  \"clientId\": \"ID:xx.xx.net-57901-1294599217160-5:3943\",\n  \"userName\": \"\",\n  \"password\": \"\",\n  \"brokerMasterConnector\": false,\n  \"manageable\": false,\n  \"clientMaster\": true,\n  \"faultTolerant\": false,\n  \"failoverReconnect\": false\n}}",
 @command="MESSAGE",
 @headers=
  {"timestamp"=>"0",
   "message-id"=>
    "ID:xx.xx.net-57901-1294599217160-2:0:0:0:63185",
   "expires"=>"0",
   "destination"=>"/topic/ActiveMQ.Advisory.Connection",
   "priority"=>"0",
   "type"=>"Advisory",
   "originBrokerURL"=>"tcp://xx.xx.net:6166",
   "originBrokerId"=>"ID:xx.xx.net-57901-1294599217160-0:0",
   "originBrokerName"=>"xx-xx"},
 @original=
  "MESSAGE\nmessage-id:ID:xx.xx.net-57901-1294599217160-2:0:0:0:63185\noriginBrokerName:xx-xx\ntype:Advisory\ndestination:/topic/ActiveMQ.Advisory.Connection\ntimestamp:0\nexpires:0\npriority:0\noriginBrokerURL:tcp://xx.xx.net:6166\noriginBrokerId:ID:xx.xx.net-57901-1294599217160-0:0\n\n{\"ConnectionInfo\": {\n  \"commandId\": 0,\n  \"responseRequired\": true,\n  \"connectionId\": {\n    \"value\": \"ID:xx.xx.net-57901-1294599217160-5:3943\"\n  },\n  \"clientId\": \"ID:xx.xx.net-57901-1294599217160-5:3943\",\n  \"userName\": \"\",\n  \"password\": \"\",\n  \"brokerMasterConnector\": false,\n  \"manageable\": false,\n  \"clientMaster\": true,\n  \"faultTolerant\": false,\n  \"failoverReconnect\": false\n}}\000">
====================

Untitled Ruby (13-Jan @ 15:41)

ripienaar.devco.net

Syntax Highlighted Code

  1. class ipsec::servers::monitor1 {
  2.     $clients = search_nodes("{'classes' => 'ipsec::endpoint::monitor1'}")
  3.  
  4.     ipsec::endpoints_from_nodes{$clients: }
  5. [20 more lines...]

Plain Code

class ipsec::servers::monitor1 {
    $clients = search_nodes("{'classes' => 'ipsec::endpoint::monitor1'}")

    ipsec::endpoints_from_nodes{$clients: }
}

define ipsec::endpoints_from_nodes {
    $node = load_node($name)

    ipsec::endpoint{$node["fqdn"]:
        dest    => $node["facts"]["ipaddress"]
    }
}

define ipsec::endpoint($dest, $ensure = "present", $mode = "transport") {
    $safe_name = regsubst($name, '-', '_', 'G')

    file{"/etc/sysconfig/network-scripts/ifcfg-ipsec.${safe_name}":
        owner   => root,
        group   => root,
        mode    => 644,
        ensure  => $ensure,
        content => template("ipsec/${mode}-mode-endpoint.erb")
    }
}

Untitled ActionScript (13-Jan @ 11:30)

ripienaar.devco.net

Syntax Highlighted Code

  1. #!/usr/bin/ruby
  2.  
  3. require 'mcollective'
  4.  
  5. [6 more lines...]

Plain Code

#!/usr/bin/ruby

require 'mcollective'

include MCollective::RPC

rpc = rpcclient("rpcutil")

rpc.get_fact(:fact => "foo").each do |resp|
    puts "%40s: %s %s" % [ resp[:sender], resp[:statuscode], resp[:statusmsg]]
end

Untitled Ruby (13-Jan @ 02:57)

ripienaar.devco.net

Syntax Highlighted Code

  1. define ipsec::endpoints_from_nodes {
  2.     $node = load_node($name)
  3.  
  4.     ipsec::endpoint{$node["fqdn"]:
  5. [8 more lines...]

Plain Code

define ipsec::endpoints_from_nodes {
    $node = load_node($name)

    ipsec::endpoint{$node["fqdn"]:
        dest    => $node["facts"]["ipaddress"]
    }
}

class ipsec::servers::monitor1 {
    $clients = search_nodes("{'classes' => 'ipsec::endpoint::monitor1'}")

    ipsec::endpoints_from_nodes{$clients: }
}

Untitled Ruby (13-Jan @ 02:34)

Syntax Highlighted Code

  1. class ipsec::servers::monitor1 {
  2.     $clients = search_nodes("{'classes' => 'ipsec::endpoint::monitor1'}")
  3.  
  4.     ipsec::endpoints_from_nodes{$clients: }
  5. [8 more lines...]

Plain Code

class ipsec::servers::monitor1 {
    $clients = search_nodes("{'classes' => 'ipsec::endpoint::monitor1'}")

    ipsec::endpoints_from_nodes{$clients: }
}

define ipsec::endpoints_from_nodes {
    $node = load_node($name)

    ipsec::endpoint{$node["facts"]["fqdn"]:
        dest    => $node["facts"]["ipaddress"]
    }
}

Untitled Ruby (9-Dec @ 09:50)

Syntax Highlighted Code

  1. # traditional ways
  2. "a : bcd(1234: xyz)".gsub(/(\(\w*:)( )(\w*\))/, '\1ijk\3')
  3.  
  4.  
  5. [1 more lines...]

Plain Code

# traditional ways
"a : bcd(1234: xyz)".gsub(/(\(\w*:)( )(\w*\))/, '\1ijk\3')


# look-behind assertions
"a : bcd(1234: xyz)".gsub(/(?<=\w:) /, 'ijk')

Untitled Ruby (5-Oct @ 14:57)

Syntax Highlighted Code

  1. require 'net/http'
  2. require 'hpricot'
  3. require 'rss/maker'
  4. require 'uri'
  5. [61 more lines...]

Plain Code

require 'net/http'
require 'hpricot' 
require 'rss/maker'
require 'uri'

class EMB 
    attr_writer :realm, :user, :password

    def initialize ( realm = 'chs_programming', user='zichun', password='paksux' )
        @realm, @user, @password = realm, user, password
        @cookies = []
        @cookie_string = ''
    end
    
    def get_cookie
        http = Net::HTTP.new('smb.chs.edu.sg', 80)
        resp,data = http.post('/cgi-bin/emb/login.pl',
                    "userid=#{@user}&password=#{@password}&login=+++Login+++", 
                    {'referer'=>'http://smb.chs.edu.sg/emb/'+@realm+'/',
                     'user_agent'=>'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Gecko/2008051206 Firefox/3.0'
                     })
        resp.get_fields('set-cookie').each { |x|
            @cookies << x
            @cookie_string += x.split("\; ")[0] + "\;"
        }
        @cookie_string
    end
    def get_main
        http = Net::HTTP.new('smb.chs.edu.sg', 80)
        http.get('/cgi-bin/emb/view.pl?date', {'Cookie'=>@cookie_string})
    end
    def get_msg (link)
        url = URI.parse(link)
        http = Net::HTTP.new('smb.chs.edu.sg',80)
        http.get( url.path+'?'+url.query, {'Cookie'=>@cookie_string} )
    end
end

emb_client = EMB.new
emb_client.get_cookie
res = emb_client.get_main

version = "2.0"

content = RSS::Maker.make(version) { |m|
    m.channel.title = "EMB CHS_PROGRAMMING"
    m.channel.link = "http://smb.chs.edu.sg/emb/chs_programming"
    m.channel.description = "Extracted messages from chs_programming EMB"
    m.items.do_sort = true

    doc = Hpricot(res.body)
     
    for i in 2...(doc/"form").length
        item = m.items.new_item
        x = (doc/"form")[i]
        item.title = (x/"a").text
        item.link = "http://smb.chs.edu.sg/emb/chs_programming/"
        item.date = Time.parse(((x/"font")[0]).innerHTML.strip) 
        emb_body = Hpricot(emb_client.get_msg( x.at("a")['href'] ).body)
        item.description = emb_body.at("pre")
        item.author = (x/"td")[2].innerHTML.strip    
    end
}

$stdout.write(content)

Untitled Ruby (30-Sep @ 09:13)

rrees.wordpress.com

Syntax Highlighted Code

  1.  
  2. require 'rubygems'
  3. require 'sinatra'
  4.  
  5. [34 more lines...]

Plain Code


require 'rubygems'
require 'sinatra'

get '/' do
    haml <<END
!!!
%html
  %head
    %title Greetings
  %body
    %p Prepare to be greeted
    %form{:action => 'hello', :method => 'post'}
      %input{:type => 'text', :name => 'name'}
      %input{:type => 'submit', :value => 'Greet'}
END
end

get '/hello/:name' do
    greet(params[:name])
end

post '/hello' do
    greet(params[:name])
end

private

def greet(name)
        haml <<END
!!!
%html
  %head
    %title Greetz
  %body
    %h1 Heya!
    %p= "Hello <em> #{name} </em>"
END
end

Untitled Ruby (21-Sep @ 22:20)

Syntax Highlighted Code

  1. puts "hello World"

Plain Code

puts "hello World"

Untitled Ruby (13-Sep @ 23:31)

Syntax Highlighted Code

  1. puts "hola que tal?"

Plain Code

puts "hola que tal?"

Untitled Ruby (5-Sep @ 06:42)

Syntax Highlighted Code

  1. date();

Plain Code

date();

Untitled Ruby (27-Aug @ 10:05)

Syntax Highlighted Code

  1. p = ['a', 'b', 'c']
  2. p.each do |item|
  3.   puts item
  4. end

Plain Code

p = ['a', 'b', 'c']
p.each do |item|
  puts item
end

Untitled Ruby (28-Jul @ 10:22)

Syntax Highlighted Code

  1. before :deploy, "solr:stop"
  2. after  :deploy, "solr:start"

Plain Code

before :deploy, "solr:stop"
after  :deploy, "solr:start"

Untitled Ruby (21-Jul @ 13:05)

Syntax Highlighted Code

  1. foo = String.new
  2.  
  3.  
  4.  

Plain Code

foo = String.new


Untitled Ruby (14-Jul @ 13:55)

Syntax Highlighted Code

  1. def foo
  2. end

Plain Code

def foo
end

Untitled Ruby (14-Jul @ 06:19)

Syntax Highlighted Code

  1. dsaf

Plain Code

dsaf

Untitled Ruby (4-Jul @ 09:50)

Syntax Highlighted Code

  1. a = String.new
  2. puts a.methods

Plain Code

a = String.new
puts a.methods

Untitled Ruby (18-Jun @ 21:58)

Syntax Highlighted Code

  1. class Carro
  2.  
  3.     def initialize
  4.        
  5. [2 more lines...]

Plain Code

class Carro

    def initialize
        
    end

end

hghgfhgfh (11-Jun @ 23:53)

Syntax Highlighted Code

  1. ghhffghgfhgfhgfh

Plain Code

ghhffghgfhgfhgfh

Untitled Ruby (28-May @ 10:32)

Syntax Highlighted Code

  1. class Example
  2.   def foo
  3.     put 'bar'
  4.   end
  5. end

Plain Code

class Example
  def foo
    put 'bar'
  end
end

Untitled Ruby (27-May @ 22:53)

Syntax Highlighted Code

  1. a = 123
  2. b = 123
  3. puts a + b

Plain Code

a = 123
b = 123
puts a + b

Untitled Ruby (12-May @ 08:05)

Syntax Highlighted Code

  1. include "hpricot"

Plain Code

include "hpricot"

Untitled Ruby (10-May @ 10:48)

Syntax Highlighted Code

  1. def test
  2.   :foo => "bar"
  3. end

Plain Code

def test
  :foo => "bar"
end