HandyCache форум

Главная категория => English forum => Тема начата: truefriend-cz от 07 июня 2017, 00:43:19



Название: Monitor action to my text
Отправлено: truefriend-cz от 07 июня 2017, 00:43:19
Hi. I have question for script... i can RULES in monitor show as my definition text convert to Response?

Example:

Response: 200 OK, Rules: U.1, S.2
convert to show as red color text:
Response: Save to Cache, Rules:U.1, S.2

and for

Response: 200 OK From Cache (HC), Rules: U.20, D.2
convert to show as green color text:
Response: Load From Cache, Rules: U.20, D.2
 

Do you can help me to create? I know param "hc.monitor_string" but no idea for include how build to script.


Название: Re: Monitor action to my text
Отправлено: mai62 от 10 июня 2017, 17:30:33
Цитировать
Response: 200 OK From Cache (HC), Rules: U.20, D.2
convert to show as green color text:
Response: Load From Cache, Rules: U.20, D.2
Код:
--[[ <HCExtension>
@name          Test_color
@event      RequestHeaderReceived
</HCExtension> ]]

function RequestHeaderReceived()
  if re.find(hc.answer_header, [[200 OK From Cache (HC)]]) then
    hc.monitor_string = hc.monitor_string..'Load From Cache'
    hc.monitor_text_color = 0 + 90*256 + 0*256*256  -- Green (R+G+B)
  end
end


Название: Re: Monitor action to my text
Отправлено: truefriend-cz от 15 июня 2017, 11:28:17
No show text from this.

And second question. How add combine with apply one file type?

My script based on filetype is:
No show text in monitor
Код:
function Test()
if re.match (hc.url, [[\.(jpe?g|bmp|png|webp|gif)(\?|$)]]) then
              hc.answer_header = [[200 OK From Cache (HC)]]
              hc.monitor_string = hc.monitor_string..'Images - Cache'
            else
      hc.monitor_string = hc.monitor_string..'Images - WAN '
            end
end


This show text monitor
Код:
function Test()
  if re.match (hc.url, [[\.(jpe?g|bmp|png|webp|gif)(\?|$)]]) then
    hc.monitor_string = hc.monitor_string..'Images - From WAN '
hc.monitor_text_color = 0 + 90*256 + 0*256*256  -- Green (R+G+B)
    end
end
----------------------
And bug:
If add this:

Код:
  if re.match(hc.answer_header, [[^HTTP/1\.1\s304[^\r\n]+]]) then
    hc.monitor_string = hc.monitor_string..'Client Cache'
    hc.monitor_text_color = 4557568
  end

then show line "304 Not modified" only as green (no 304 Not modified (HC)), and "200 OK From Cache (HC)" show as green.


----------
Complette test script:

Код:
--[[ <HCExtension>
@name          Test
@description   For testing
@event         AnswerHeaderReceived
</HCExtension> ]]

function AnswerHeaderReceived()
  if re.match (hc.url, [[\.(jpe?g|bmp|png|webp|gif)(\?|$)]]) then
    hc.monitor_string = hc.monitor_string..'Images - From WAN'
hc.monitor_text_color = 0 + 90*256 + 0*256*256  -- Green (R+G+B)
  end
  if re.find(hc.answer_header, [[200 OK From Cache (HC)]]) then
    hc.monitor_string = hc.monitor_string..'Images - Cache'
    hc.monitor_text_color = 0 + 90*256 + 0*256*256  -- Green (R+G+B)
  end
  if re.match(hc.answer_header, [[^HTTP/1\.1\s304[^\r\n]+]]) then
    hc.monitor_string = hc.monitor_string..'Client Cache'
    hc.monitor_text_color = 0 + 90*256 + 0*256*256  -- Green (R+G+B)
  end
end

function Test()
if re.match (hc.url, [[\.(jpe?g|bmp|png|webp|gif)(\?|$)]]) then
              hc.answer_header = [[200 OK From Cache (HC)]]
              hc.monitor_string = hc.monitor_string..'Images - Cache'
            else
          hc.monitor_string = hc.monitor_string..'Images - WAN'
            end
end


Название: Re: Monitor action to my text
Отправлено: truefriend-cz от 15 июня 2017, 14:19:27
Mai62 where is problem?

I run two testing script, but no solutions. How worked RequestHeaderReceived?

Код:
--[[ <HCExtension>
@name          Test
@event       RequestHeaderReceived
</HCExtension> ]]

function RequestHeaderReceived()
    if not re.find(hc.request_header, [[Cache]]) then
    hc.monitor_string = hc.monitor_string..'Test RequestHeaderReceived OK'
end

Код:
--[[ <HCExtension>
@name          Test
@event       RequestHeaderReceived
</HCExtension> ]]

function RequestHeaderReceived()
    if re.find(hc.request_header, [[Cache]]) then
    hc.monitor_string = hc.monitor_string..'Test RequestHeaderReceived OK'
end


Название: Re: Monitor action to my text
Отправлено: mai62 от 17 июня 2017, 13:06:31
I made a mistake. You do not need to use RequestHeaderReceived, but AnswerHeaderReceived and hc.answer_header.
Код:
--[[ <HCExtension>
@name          Test
@event       AnswerHeaderReceived
</HCExtension> ]]

function AnswerHeaderReceived ()
    if not re.find(hc.answer_header, [[Cache]]) then
    hc.monitor_string = hc.monitor_string..'Test AnswerHeaderReceived OK'
end


Название: Re: Monitor action to my text
Отправлено: truefriend-cz от 19 июня 2017, 13:45:14
Thanks. Version HC 1.0.0.671 maybe have bug. Version 1.0.0.571 and etc..

I tested on original Rev5 script Extension... on clean HC (all other Extensions disabled). Only on 1.0.0.671 no show colors and "my texts" in monitor.


Название: Re: Monitor action to my text
Отправлено: truefriend-cz от 21 июня 2017, 14:53:15
Thank you very much :)