用Netscaler的Variable和Assignment来实现计数控制
用Netscaler的Variable和Assignment来实现计数控制
Variable变量和Assignment调度的手册:
https://docs.citrix.com/en-us/netscaler/11-1/appexpert/variables.html
在负载均衡做各种复杂策略的时候往往会碰到需要前后有连续性的状态计数,netscaler作为一个策略封装比较友好的ADC在提供完善策略安全性保障的同时还提供了比较开放的编程环境。在编程中很关键的一环就是变量的定义和使用,我们就变量这一话题来看netscaler能够提供怎样的功能。本文抛砖引玉为目的,提供一个思路供大家参考,具体应用场景还需要大家发散性思考。
定义变量
长整型: ------------------------------- 数组型:
add ns variable name_variable -type ulong -init 1 -expires 3600
add ns variable my_variable -type "map(text(20),ulong,500)" -init 15 -expires 600
调用变量进行计算
进行计算的方式有如下:add加法、set重设成某个值、sub减法、append附加、clear清除
add ns assignment name_assign_add -variable "$name_variable" -add 1
add ns assignment my_assign -variable "$my_variable[HTTP.REQ.HEADER(\"CJ_Cookie\")]" -add 1
计算好的变量Variable可以在Policy里当Action使用,或者在表达式中来做判断依据
调用的方法如下:$variable_name.valueExists.其他表达式(返回布尔值)或$variable_name.valueCount.其他表达式(返回数值)
$name.valueExists(key-expression). Returns true if there is a value in the map selected by the key-expression. Otherwise returns false. This function will update the expiration and LRU information if the map entry exists, but will not create a new map entry if the value does not exist.
$name.valueCount. Returns the number of values currently held by the variable. This is the number of entries in a map. For a singleton variable, this is 0 if the variable is uninitialized or 1 otherwise.
例如:
$name_variable.GE(10);
$my_variable.valueCount.EQ(10)
add rewrite action rw_action_variable_waring2 insert_after_all "HTTP.RES.BODY(59999).SET_TEXT_MODE(IGNORECASE)" "\"this is waring\"" -pattern "随波汉化版"
add rewrite policy rw_policy_variable_waring "$name_variable.GE(10)" rw_action_variable_waring2
实现效果:当变量大于10的时候执行插入body的动作
或着在action中定义插入一个cookie值,名字为CJ_Count: 值为变量的值
add rewrite action rw_action_variable insert_http_header Set-Cookie "\"CJ_Count:\"+$name_variable"
测试案例use case:
定义变量,做为计数用户访问或登录次数
add ns variable name_variable -type ulong -init 1 -expires 3600
add ns variable name_variable_dele -type ulong -init 1 -expires 3600
调用两个变量并计算:
name_assign_add 每次增加1 ------------------ name_assign_dele 每次把变量清除
add ns assignment name_assign_add -variable "$name_variable" -add 1
add ns assignment name_assign_dele -variable "$name_variable" -clear
Rewrite策略:
rewrite策略实现访问URL=03时,variable增加1,访问URL=callout时,variable清除;请求header中Accetp为text时插入COOKIE
add rewrite policy rw_policy_variable "HTTP.REQ.HEADER(\"Accept\").CONTAINS(\"text\")" rw_action_variable
add rewrite policy rw_policy_variable_add "HTTP.REQ.URL.PATH.GET(1).EQ(\"03\")" name_assign_add
add rewrite policy rw_policy_variable_dele "HTTP.REQ.URL.PATH.GET(1).EQ(\"callout\")" name_assign_dele
action为:插入cookie,名字为CJ_Count,值为变量的值
add rewrite action rw_action_variable insert_http_header Set-Cookie "\"CJ_Count:\"+$name_variable"
效果:
登录主页时,由于accept为text,遂插入cookie:CJ_Cookie=1
每次访问URL=/03时Cookie的值+1
访问URL=/callout时,把cookie的值清除
转载于:https://blog.51cto.com/caojin/2061350
用Netscaler的Variable和Assignment来实现计数控制相关推荐
- Java | Assignment Statements Expressions
An assignment statement designates a value for a variable. An assignment statement(赋值语句) can be used ...
- SAP HR模块复制PA30的人员
很多顾问测试HR的程序时都为录入人员头痛,下面的程序提供了快速复制人员的方法. 代码如下: *&------------------------------------------------ ...
- JPDL3.1规范手册
JPDL3.1规范手册 jBPM业务程序定义语言(jBPM Process Definition Language (JPDL)) ...
- python 面试问题_值得阅读的30个Python面试问题
python 面试问题 Interview questions are quite tricky to predict. In most cases, even peoples with great ...
- 深入理解JavaScript内部原理(5): function
本文是翻译http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/#introduction 概要 In this article we w ...
- python变量_Python变量
python变量 In this tutorial we will know some basics about Python Variable. In our previous tutorial w ...
- Bulletproof零知识证明
如何使用dalek-cryptography中的Bulletproofs实现(Bulletproofs implementation)[1]创建各种零知识证明.示例为i)证明自己知道给定数字的因数而不 ...
- r语言和rstudio_R和RStudio简介
r语言和rstudio With increased computing power comes increased access to large amounts of freely accessi ...
- [books] - SICP 2nd edition
全名是: Structure and Interpretation of Computer Programs 中文名稱: 计算机程序的构造和解释 20131024 淘寶訂單 20131104 到手, ...
最新文章
- 信号完整性(四):信号振铃是怎么产生的
- 优化内核报错及解决方法
- python包pip安装_python包管理之Pip安装及使用
- Spring3 文件上传
- PPP、MP 和 SLIP 配置(上)
- 南邮CTF-MISC-Remove Boyfriend
- sqlldr 导入乱码,Oracle客户端字符集问题
- 下血本买的!2021Java高级面试题
- 【聊透SpringMVC】28天肝完阿里面试通关宝典
- 测试测量(3)- 如何选择设备的平台
- 梦幻家园前37关(iPad)
- 安卓开发实现悬浮窗显示(全局显示),通过悬浮窗实时监控当前流量
- 机顶盒App安装在sd卡的目录
- 艾肯6nano声卡安装调试教程
- datagrid的deleteRow使用
- iOS包体积优化实践
- 惯性动作捕捉系统在虚拟主播中的应用
- 刷脸支付在流量金贵时代把控千万用户
- Stata画出数据的时间序列折线图和拟合趋势线
- 利用EXCEL函数LINEST进行统计学中的回归分析
热门文章
- redis 用setbit(bitmap)统计活跃用户
- android NDK 二、编译方法
- iOS中GCD的魔力
- 我国数字出版发展尚存三大难题
- 苹果工具条_苹果发布iOS 13.4首个测试版:能让iPhone变身为车钥匙
- 解决binwalk运行提示缺少LZMA模块
- Kali Linux WPScan更新到2.9.3
- ​Highmaps网页图表教程之绘图区显示标签显示数据标签定位
- HealthKit开发快速入门教程之HealthKit开发概述简介
- oracle19c主目录用户,oracle 19c 添加 scott用户与表